134 lines
5.5 KiB
C#
134 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Web.Http;
|
|
using System.Web.Http.ModelBinding;
|
|
using System.Web.Http.Results;
|
|
using Kendo.Mvc.UI;
|
|
using Kreta.BusinessLogic.Classes.ComboBox;
|
|
using Kreta.BusinessLogic.HelperClasses;
|
|
using Kreta.BusinessLogic.Helpers;
|
|
using Kreta.BusinessLogic.Security;
|
|
using Kreta.BusinessLogic.Utils;
|
|
using Kreta.Enums;
|
|
using Kreta.Framework;
|
|
using Kreta.Framework.Util;
|
|
using Kreta.Resources;
|
|
using Kreta.Web.Areas.Adatszolgaltatasok.Models;
|
|
using Kreta.Web.Helpers;
|
|
using Kreta.Web.Helpers.Error;
|
|
using Kreta.Web.Helpers.Grid;
|
|
using Kreta.Web.Security;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Kreta.Web.Areas.Adatszolgaltatasok.ApiControllers
|
|
{
|
|
[ApiRoleClaimsAuthorize(true)]
|
|
[ApiRolePackageAuthorize(KretaClaimPackages.Adminisztrator.ClaimValue)]
|
|
public class KozmuszamlaApiController : ApiController
|
|
{
|
|
public DataSourceResult GetKozmuszamlaGrid(string data, [ModelBinder(typeof(ModelBinder.DataSourceRequestModelBinder))] DataSourceRequest request)
|
|
{
|
|
KozmuszamlaSearchModel model = JsonConvert.DeserializeObject<KozmuszamlaSearchModel>(data);
|
|
|
|
var kozmuszamlaHelper = new KozmuszamlaHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
|
|
|
kozmuszamlaHelper.GridParameters = Converter.GridParameter(request);
|
|
|
|
var kozmuszamlaList = kozmuszamlaHelper.KozmuszamlaKereses(model.FizetesiHataridoTolSearch, model.FizetesiHataridoIgSearch, model.IsFizetveSearch, model.KibocsatoSearch, model.KozmuSzamlaTipusIdSearch, model.OsszegTolSearch, model.OsszegIgSearch);
|
|
return kozmuszamlaList.ToDataSourceResult();
|
|
}
|
|
|
|
public JsonResult<List<ComboBoxListItem>> GetKozmuszamlaTipusList([DataSourceRequest] DataSourceRequest request)
|
|
{
|
|
return Json(((int)GeneratedAdatszotarTipusEnum.KozmuSzamlaTipus).GetItemsByType(ClaimData.SelectedTanevID.Value, true).ToComboBoxItemList());
|
|
}
|
|
|
|
[HttpPost]
|
|
public HttpResponseMessage SaveKozmuszamla(KozmuszamlaModel model)
|
|
{
|
|
ValidateModel(model);
|
|
|
|
if (ModelState.IsValid)
|
|
{
|
|
try
|
|
{
|
|
KozmuszamlaCO KozmuszamlaCo = ConvertKozmuszamlaModelToCo(model);
|
|
new KozmuszamlaHelper(ConnectionTypeExtensions.GetSessionConnectionType()).SaveKozmuszamla(KozmuszamlaCo);
|
|
}
|
|
catch (KretaError kretaError)
|
|
{
|
|
SDAServer.Instance.Logger.ExceptionThrown(kretaError);
|
|
ModelState.AddModelError("Error", kretaError.Message);
|
|
}
|
|
|
|
if (ModelState.IsValid)
|
|
{
|
|
return new HttpResponseMessage(HttpStatusCode.OK);
|
|
}
|
|
}
|
|
var httpResponseMessage = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
|
return httpResponseMessage;
|
|
}
|
|
|
|
private KozmuszamlaCO ConvertKozmuszamlaModelToCo(KozmuszamlaModel model)
|
|
{
|
|
return new KozmuszamlaCO
|
|
{
|
|
Id = model.Id,
|
|
BefizetesDatuma = model.BefizetesDatuma,
|
|
FizetesiHatarido = model.FizetesiHatarido,
|
|
Fizetve = model.Fizetve == 1 || model.BefizetesDatuma.HasValue,
|
|
InvaliditasOka = model.InvaliditasOka,
|
|
Kelte = model.Kelte,
|
|
Kibocsato = model.Kibocsato,
|
|
KozmuszamlaTipusId = model.KozmuszamlaTipusId,
|
|
Osszeg = model.Osszeg,
|
|
PenznemId = model.PenznemId,
|
|
MerohelyId = model.MerohelyId.Value
|
|
};
|
|
}
|
|
|
|
[HttpPost]
|
|
public HttpResponseMessage DeleteKozmuszamla([FromBody] int id)
|
|
{
|
|
try
|
|
{
|
|
new KozmuszamlaHelper(ConnectionTypeExtensions.GetActiveSessionConnectionType()).DeleteKozmuszamlaById(id);
|
|
return new HttpResponseMessage(HttpStatusCode.OK);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
throw new StatusError(HttpStatusCode.InternalServerError,
|
|
StringResourcesUtil.GetString(4358) /*Hiba történt törlés közben!*/)
|
|
{
|
|
UnHandledException = exception
|
|
};
|
|
}
|
|
}
|
|
|
|
private void ValidateModel(KozmuszamlaModel model)
|
|
{
|
|
if (model.Kelte.HasValue && model.FizetesiHatarido.HasValue && model.Kelte.Value > model.FizetesiHatarido.Value)
|
|
{
|
|
ModelState.AddModelError(nameof(KozmuszamlaModel.Kelte), ErrorResource.SzamlaKelteNemLehetKesobbMintAFizetesiHatarido);
|
|
}
|
|
|
|
if (model.Kelte.HasValue && model.BefizetesDatuma.HasValue && model.Kelte.Value > model.BefizetesDatuma.Value)
|
|
{
|
|
ModelState.AddModelError(nameof(KozmuszamlaModel.Kelte), ErrorResource.SzamlaKelteNemLehetKesobbMintABefizetesiDatum);
|
|
}
|
|
|
|
if (model.BefizetesDatuma.HasValue && model.FizetesiHatarido.HasValue && model.BefizetesDatuma.Value > model.FizetesiHatarido.Value)
|
|
{
|
|
ModelState.AddModelError(nameof(KozmuszamlaModel.BefizetesDatuma), ErrorResource.BefizetesDatumaNemLehetKesobbMintAFizetesiHatarido);
|
|
}
|
|
|
|
if (model.Fizetve.HasValue && model.Fizetve != default(int) && !model.BefizetesDatuma.HasValue)
|
|
{
|
|
ModelState.AddModelError(nameof(KozmuszamlaModel.BefizetesDatuma), ErrorResource.FizetveJelolesEsetenBefizetesDatumaKotelezo);
|
|
}
|
|
}
|
|
}
|
|
}
|