kreta/KretaWeb/Areas/Hianyzas/ApiControllers/BaseIgazolasokApiController.cs
2024-03-13 00:33:46 +01:00

66 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.ModelBinding;
using Kendo.Mvc.UI;
using Kreta.BusinessLogic.Classes;
using Kreta.BusinessLogic.HelperClasses;
using Kreta.BusinessLogic.Helpers;
using Kreta.BusinessLogic.Security;
using Kreta.Framework.Entities;
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 BaseIgazolasokApiController : ApiController
{
[NonAction]
public DataSourceResult GetDetailIgazolasok(int tanuloId, [ModelBinder(typeof(ModelBinder.DataSourceRequestModelBinder))] DataSourceRequest request, int? szervezetTipusId = null)
{
var authorization = (IKretaAuthorization)Request.GetDependencyScope().GetService(typeof(IKretaAuthorization));
if (!authorization.IsValidTanulo(tanuloId))
{
throw new StatusError(HttpStatusCode.Forbidden, ErrorResource.AFelhasznalonakNincsMegfeleloJogosultsagaAFunkcioHasznalatahoz);
}
var helper = new IgazolasHelper(ConnectionTypeExtensions.GetActiveSessionConnectionType());
helper.GridParameters = Converter.GridParameter(request);
DataSet ds = helper.IgazolasDetailKereses(tanuloId, szervezetTipusId);
return ds.ToDataSourceResult();
}
[NonAction]
public DataSourceResult GetIgazolasGrid(string data, [ModelBinder(typeof(ModelBinder.DataSourceRequestModelBinder))] DataSourceRequest request, int? szervezetTipusId = null)
{
var model = JsonConvert.DeserializeObject<IgazolasKeresoModel>(data);
if (!model.OsztCsopId.HasValue)
{
return new DataSourceResult();
}
var authorization = (IKretaAuthorization)Request.GetDependencyScope().GetService(typeof(IKretaAuthorization));
if (!authorization.IsValidOsztalyCsoport(model.OsztCsopId.Value))
{
throw new StatusError(HttpStatusCode.Forbidden, ErrorResource.AFelhasznalonakNincsMegfeleloJogosultsagaAFunkcioHasznalatahoz);
}
IgazolasHelper helper = new IgazolasHelper(ConnectionTypeExtensions.GetActiveSessionConnectionType());
helper.GridParameters = Converter.GridParameter(request);
DataSet ds = helper.IgazolasKereses(model.OsztCsopId, szervezetTipusId);
return ds.ToDataSourceResult();
}
}
}