125 lines
4.5 KiB
C#
125 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Web.Http;
|
|
using System.Web.Http.Results;
|
|
using Kendo.Mvc.UI;
|
|
using Kreta.BusinessLogic.Classes.ComboBox;
|
|
using Kreta.BusinessLogic.Helpers;
|
|
using Kreta.BusinessLogic.Logic;
|
|
using Kreta.BusinessLogic.Utils;
|
|
using Kreta.Core;
|
|
using Kreta.Enums;
|
|
using Kreta.Enums.ManualEnums;
|
|
using Kreta.Framework.Entities;
|
|
using Kreta.Framework.Util;
|
|
using Kreta.Resources;
|
|
using Kreta.Web.Areas.Hianyzas.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.Hianyzas.ApiControllers
|
|
{
|
|
public class BaseMulasztasKeresoApiController : ApiController
|
|
{
|
|
[NonAction]
|
|
public HttpResponseMessage GetExport(string data, DataSourceRequest request, SzervezetTipusEnum? szervezetTipus = null)
|
|
{
|
|
try
|
|
{
|
|
var (gridParameter, modelList) = GetGridData(data, request, szervezetTipus);
|
|
|
|
modelList = modelList.SortingAndPaging(gridParameter.OrderDictionary);
|
|
|
|
var simpleExportColumnCos = SimpleExportLogic.GetSimpleExportColumnCos<MulasztasGridModel>(MulasztasGridModel.MulasztasExportAttributeId);
|
|
|
|
var memoryStream = SimpleExportLogic.GetExport(MulasztasResource.ExportDefaultSheetname, simpleExportColumnCos, modelList, ClaimData.SelectedTanevID.Value);
|
|
|
|
return HttpResponseExtensions.GetFileHttpResponse(memoryStream.ToArray(), MulasztasResource.ExportFileName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new StatusError(HttpStatusCode.BadRequest, ErrorResource.HibaTortentAFajlExportalasaKozben) { UnHandledException = ex };
|
|
}
|
|
}
|
|
|
|
public (GridParameters gridParameter, List<MulasztasGridModel> modelList) GetGridData(string data, DataSourceRequest request, SzervezetTipusEnum? szervezetTipus = null)
|
|
{
|
|
var model = JsonConvert.DeserializeObject<MulasztasSearchModel>(data);
|
|
|
|
if (szervezetTipus.HasValue)
|
|
{
|
|
model.SzervezetTipusId = (int)szervezetTipus;
|
|
}
|
|
|
|
var gridParameter = Converter.GridParameter(request);
|
|
|
|
var coList = new MulasztasHelper(ConnectionTypeExtensions.GetSessionConnectionType()).GetMulasztasCoList(model.ConvertModelToCo(), true);
|
|
|
|
var modelList = new List<MulasztasGridModel>();
|
|
foreach (var co in coList)
|
|
{
|
|
var gridModel = new MulasztasGridModel(co);
|
|
modelList.Add(gridModel);
|
|
}
|
|
|
|
return (gridParameter, modelList);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ApiValidateAjaxAntiForgeryToken]
|
|
public HttpResponseMessage DeleteMulasztas([FromBody] int id)
|
|
{
|
|
try
|
|
{
|
|
var helper = new MulasztasHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
|
helper.DeleteMulasztasById(id);
|
|
|
|
return new HttpResponseMessage(HttpStatusCode.OK);
|
|
}
|
|
catch (EntityDeleteFailedException ex)
|
|
{
|
|
var uzenet = string.Format(ErrorResource.NemTorolhetoKapcsolatMiatt, TanuloErtekelesResource.Ertekeles, ex.ConnectionErrorMessage);
|
|
throw new StatusError(HttpStatusCode.BadRequest, uzenet);
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
[ApiValidateAjaxAntiForgeryToken]
|
|
public HttpResponseMessage DeleteTobbesMulasztas([FromBody] int[] ids)
|
|
{
|
|
try
|
|
{
|
|
var helper = new MulasztasHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
|
foreach (var id in ids)
|
|
{
|
|
helper.DeleteMulasztasById(id);
|
|
}
|
|
|
|
return new HttpResponseMessage(HttpStatusCode.OK);
|
|
}
|
|
catch (EntityDeleteFailedException ex)
|
|
{
|
|
var uzenet = string.Format(ErrorResource.NemTorolhetoKapcsolatMiatt, TanuloErtekelesResource.Ertekeles, ex.ConnectionErrorMessage);
|
|
throw new StatusError(HttpStatusCode.BadRequest, uzenet);
|
|
}
|
|
|
|
}
|
|
|
|
public JsonResult<List<ComboBoxListItem>> GetIgazoltList()
|
|
{
|
|
var items = new Dictionary<string, string>
|
|
{
|
|
{ "0", HianyzasResource.Igazolatlan },
|
|
{ "1", HianyzasResource.Igazolt },
|
|
{ "2", HianyzasResource.Igazolando }
|
|
};
|
|
return Json(items.ToComboBoxItemList());
|
|
}
|
|
}
|
|
}
|