359 lines
18 KiB
C#
359 lines
18 KiB
C#
using System;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Web.Http;
|
|
using Kreta.BusinessLogic.Classes;
|
|
using Kreta.BusinessLogic.HelperClasses;
|
|
using Kreta.BusinessLogic.Helpers;
|
|
using Kreta.BusinessLogic.Helpers.SystemSettings;
|
|
using Kreta.BusinessLogic.Interfaces;
|
|
using Kreta.BusinessLogic.Logic.Naplozas;
|
|
using Kreta.BusinessLogic.Logic.Naplozas.Validacio;
|
|
using Kreta.Client.CoreApi;
|
|
using Kreta.Core.Exceptions;
|
|
using Kreta.Enums;
|
|
using Kreta.Enums.ManualEnums;
|
|
using Kreta.Framework;
|
|
using Kreta.Resources;
|
|
using Kreta.Web.Areas.Orarend.Models;
|
|
using Kreta.Web.Helpers;
|
|
using Kreta.Web.Helpers.Error;
|
|
using Kreta.Web.Security;
|
|
|
|
namespace Kreta.Web.Areas.Orarend.ApiControllers
|
|
{
|
|
public class BaseTanariOrarendApiController : ApiController
|
|
{
|
|
private IKretaAuthorization Authorization { get; }
|
|
private readonly IFileServiceHelper _fileServiceHelper;
|
|
private readonly ICoreApiClient _coreApiClient;
|
|
|
|
public BaseTanariOrarendApiController(IKretaAuthorization authorization, IFileServiceHelper fileServiceHelper, ICoreApiClient coreApiClient)
|
|
{
|
|
Authorization = authorization;
|
|
_fileServiceHelper = fileServiceHelper ?? throw new ArgumentNullException(nameof(fileServiceHelper));
|
|
_coreApiClient = coreApiClient ?? throw new ArgumentNullException(nameof(coreApiClient));
|
|
}
|
|
|
|
[NonAction]
|
|
public IHttpActionResult ValidateNaplozas(TanoraNaplozasRogzites model, int? szervezetTipusId = null)
|
|
{
|
|
if (model.MulasztasNaplozasRogzites.Tema == null)
|
|
{
|
|
return Json(new { ModelState = new { Tema = new[] { ErrorResource.OraTemajanakKivalasztasaVagyATemaMegadasaKotelezo } } });
|
|
}
|
|
|
|
var connectionType = ConnectionTypeExtensions.GetSessionConnectionType();
|
|
|
|
var naploValidacioParameters = new NaploValidacioParameters(model.TanoraMuveletek.CalendarModel.Start, connectionType, ClaimData.FelhasznaloSzerepkor);
|
|
var validator = new NaploValidacio(naploValidacioParameters);
|
|
|
|
var co = new NaplozasCo();
|
|
model.ConvertTo(co, model.TanoraMuveletek.NaplozasDatum);
|
|
co.SzervezetTipusId = szervezetTipusId;
|
|
var naplozasLogic = new NaplozasLogic(validator, co);
|
|
|
|
bool utkozik = false;
|
|
if (model.TanoraMuveletek.CalendarModel.EventType != EventTypeEnum.LetezoOraSzerkesztese)
|
|
{
|
|
utkozik = !co.OraAdat.OrarendiOraId.HasValue && naplozasLogic.TeremUtkozesEllenorzes();
|
|
}
|
|
|
|
var systemSettingsHelper = new SystemSettingsHelper(connectionType);
|
|
var teremHelper = new TeremHelper(connectionType);
|
|
if (!szervezetTipusId.HasValue)
|
|
{
|
|
if (IsTeremBefogadokepessegeKissebbMintAzOsztalyCsoportLetszama(systemSettingsHelper, teremHelper, model.TanoraAdatokRogzites.TeremId, model.MulasztasNaplozasRogzites.MulasztasList.Count))
|
|
{
|
|
if (utkozik)
|
|
{
|
|
return Json(new { Valid = false, Text = OrarendResource.TeremutkozesEsTeremBefogadokepessegeKisebb });
|
|
}
|
|
|
|
return Json(new { Valid = false, Text = OrarendResource.ATeremBefogadokepessegeKisebbMintAzOsztalyCsoportLetszamaSzeretneFolytatni });
|
|
}
|
|
}
|
|
|
|
if (naplozasLogic.GetModel.IsTanora && !model.TanoraMuveletek.CalendarModel.IsOraOsszevonas && model.TanoraMuveletek.CalendarModel.EventType != EventTypeEnum.LetezoOraSzerkesztese)
|
|
{
|
|
var osztalyVagyTanarOraiadottUtkozes = naplozasLogic.GetOsztalyEsTanarOraiUtkozes();
|
|
|
|
var tevekenysegUtkozes = systemSettingsHelper.GetSystemSettingValue<int>(RendszerBeallitasTipusEnum.Napirend_felvitelel_utkozes_figyeles);
|
|
|
|
switch ((TevekenysegUtkozesEnum)tevekenysegUtkozes)
|
|
{
|
|
case TevekenysegUtkozesEnum.UtkozesNemLehetseges: /*Ütközés nem lehetséges*/
|
|
if (!string.IsNullOrWhiteSpace(osztalyVagyTanarOraiadottUtkozes))
|
|
{
|
|
throw new StatusError(HttpStatusCode.BadRequest, string.Format(OrarendResource.TanoraFelviteleNemLehetsegesUtkozesMiatt, osztalyVagyTanarOraiadottUtkozes));
|
|
}
|
|
|
|
break;
|
|
case TevekenysegUtkozesEnum.UtkozeskorFigyelmeztetes: /*Figyelmeztetés*/
|
|
{
|
|
if (utkozik && !string.IsNullOrWhiteSpace(osztalyVagyTanarOraiadottUtkozes))
|
|
{
|
|
return Json(new { Valid = false, Text = string.Format(OrarendResource.TanoraFelviteleNemLehetsegesUtkozesMiattKerdes, OrarendResource.Teremutkozes, OrarendResource.OraUtkozes, osztalyVagyTanarOraiadottUtkozes) });
|
|
}
|
|
|
|
if (utkozik)
|
|
{
|
|
return Json(new { Valid = false, Text = string.Format(OrarendResource.TanoraFelviteleNemLehetsegesUtkozesMiattKerdes, OrarendResource.Teremutkozes, string.Empty, string.Empty) });
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(osztalyVagyTanarOraiadottUtkozes))
|
|
{
|
|
return Json(new { Valid = false, Text = string.Format(OrarendResource.TanoraFelviteleNemLehetsegesUtkozesMiattKerdes, string.Empty, OrarendResource.OraUtkozes, osztalyVagyTanarOraiadottUtkozes)/*A naplózandó óra időtartamába egy már naplózott óra, vagy órarendi óra is beleesik, szeretné folytatni?*/ });
|
|
}
|
|
}
|
|
|
|
break;
|
|
case TevekenysegUtkozesEnum.UtkozesMegengedett: /*Ütközés lehetséges, nem kell a napirend miatt szólni*/
|
|
if (utkozik)
|
|
{
|
|
return Json(new { Valid = false, Text = StringResourcesUtil.GetString(4613)/*Terem ütközés lépett fel szeretné folytatni?*/ });
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
return Json(new { Valid = true, Text = "" });
|
|
}
|
|
|
|
[NonAction]
|
|
public HttpResponseMessage SaveNaplozas(TanoraNaplozasRogzites model, int? szervezetTipusId = null)
|
|
{
|
|
var startDate = model.TanoraMuveletek.CalendarModel.Start;
|
|
model.TanoraAdatokRogzites.OraKezdete = new DateTime(startDate.Year, startDate.Month, startDate.Day, model.TanoraAdatokRogzites.OraKezdete.Hour, model.TanoraAdatokRogzites.OraKezdete.Minute, 0, DateTimeKind.Utc).ToLocalTime();
|
|
|
|
var endDdate = model.TanoraMuveletek.CalendarModel.End;
|
|
model.TanoraAdatokRogzites.OraVege = new DateTime(endDdate.Year, endDdate.Month, endDdate.Day, model.TanoraAdatokRogzites.OraVege.Hour, model.TanoraAdatokRogzites.OraVege.Minute, 0, DateTimeKind.Utc).ToLocalTime();
|
|
|
|
NaplozasResultCo saveResult = null;
|
|
if (!model.TanoraAdatokRogzites.IsMegtartott)
|
|
{
|
|
LicenceHelper.LicenceWait(ClaimData.LicenceDatum);
|
|
var res = SaveNemMegtartottNaplozas(model, szervezetTipusId);
|
|
return res;
|
|
}
|
|
|
|
if (!model.TanoraMuveletek.IsTanoranKivuli)
|
|
{
|
|
if (model.TanoraMuveletek.CalendarModel.OraType == CalendarOraTypeEnum.TanitasiOra
|
|
&& (!model.TanoraAdatokRogzites.CsengetesiRendID.HasValue || model.TanoraAdatokRogzites.CsengetesiRendID < 0))
|
|
{
|
|
var helper = new CsengetesiRendHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
|
model.TanoraAdatokRogzites.CsengetesiRendID = helper.GetAktivCsengetesiRendId();
|
|
}
|
|
|
|
if (!model.TanoraAdatokRogzites.CsengetesiRendID.HasValue || model.TanoraAdatokRogzites.CsengetesiRendID < 0)
|
|
{
|
|
ModelState.AddModelError(nameof(model.TanoraAdatokRogzites.CsengetesiRendID), OrarendResource.CsengetesiRendMegadasaKotelezo);
|
|
}
|
|
|
|
if (!model.TanoraAdatokRogzites.Oraszam.HasValue || model.TanoraAdatokRogzites.Oraszam < 0)
|
|
{
|
|
ModelState.AddModelError(nameof(model.TanoraAdatokRogzites.Oraszam), OrarendResource.OraszamMegadasaKotelezo);
|
|
}
|
|
|
|
if (model.TanoraAdatokRogzites.Oraszam.HasValue && model.TanoraAdatokRogzites.CsengetesiRendID.HasValue)
|
|
{
|
|
var (minOraszam, maxOraszam) = Logic.OrarendiOraLogic.GetMinMaxOraszam(model.TanoraAdatokRogzites.CsengetesiRendID.Value);
|
|
if (model.TanoraAdatokRogzites.Oraszam > maxOraszam || model.TanoraAdatokRogzites.Oraszam < minOraszam)
|
|
{
|
|
ModelState.AddModelError(nameof(model.TanoraAdatokRogzites.Oraszam), string.Format(OrarendResource.OraszamError, minOraszam.ToString(), maxOraszam.ToString()));
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (Logic.OrarendiOraLogic.CreateLocalDateTimeBasedOnDateAndTime(model.TanoraMuveletek.CalendarModel.Start, model.TanoraMuveletek.CalendarModel.Start).TimeOfDay >=
|
|
Logic.OrarendiOraLogic.CreateLocalDateTimeBasedOnDateAndTime(model.TanoraMuveletek.CalendarModel.End, model.TanoraMuveletek.CalendarModel.End).TimeOfDay)
|
|
{
|
|
ModelState.AddModelError(nameof(model.TanoraAdatokRogzites.OraVege), ErrorResource.NapirendKezdetiIdopontjaNemLehetKesobbMintAZaroIdopont);
|
|
}
|
|
}
|
|
|
|
if (model.MulasztasNaplozasRogzites.MulasztasList.Exists(x => x.MulasztasTipus == (int)MulasztasTipusEnum.keses && (x.Keses == null || x.Keses == 0)))
|
|
{
|
|
ModelState.AddModelError(string.Empty, ErrorResource.AKesesekHosszanakKitolteseKotelezo);
|
|
}
|
|
|
|
if (!model.MulasztasNaplozasRogzites.TemaTanmenetId.HasValue || (model.MulasztasNaplozasRogzites.TemaTanmenetId == -1))
|
|
{
|
|
if (string.IsNullOrWhiteSpace(model.MulasztasNaplozasRogzites.Tema))
|
|
{
|
|
ModelState.AddModelError(nameof(model.MulasztasNaplozasRogzites.Tema), ErrorResource.OraTemajanakKivalasztasaVagyATemaMegadasaKotelezo);
|
|
}
|
|
else if (model.MulasztasNaplozasRogzites.Tema.Length > 1000) /*db ben ez a max char jelenleg*/
|
|
{
|
|
ModelState.AddModelError(nameof(model.MulasztasNaplozasRogzites.Tema), ErrorResource.TemaTulHosszu);
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(model.HaziFeladatNaplozasRogzites?.HaziFeladat) && model.HaziFeladatNaplozasRogzites?.Hatarido == null)
|
|
{
|
|
ModelState.AddModelError(nameof(model.HaziFeladatNaplozasRogzites.Hatarido), OrarendResource.HazifeladatHataridoKotelezo);
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(model.HaziFeladatNaplozasRogzites?.HaziFeladat) && model.HaziFeladatNaplozasRogzites?.Hatarido != null)
|
|
{
|
|
ModelState.AddModelError(nameof(model.HaziFeladatNaplozasRogzites.HaziFeladat), OrarendResource.HazifeladatSzovegKotelezo);
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(model.TanoraAdatokRogzites.Megjegyzes) && model.TanoraAdatokRogzites.Megjegyzes.Length > 255)
|
|
{
|
|
ModelState.AddModelError(nameof(model.TanoraAdatokRogzites.Megjegyzes), ErrorResource.AMegjegyzesMax255KarakterLehet);
|
|
}
|
|
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
|
}
|
|
|
|
try
|
|
{
|
|
var naploValidacioParameters = new NaploValidacioParameters(model.TanoraMuveletek.CalendarModel.Start, ConnectionTypeExtensions.GetSessionConnectionType(), ClaimData.FelhasznaloSzerepkor);
|
|
var validator = new NaploValidacio(naploValidacioParameters);
|
|
var co = new NaplozasCo();
|
|
model.ConvertTo(co, model.TanoraMuveletek.NaplozasDatum);
|
|
co.SzervezetTipusId = szervezetTipusId;
|
|
var naplozasLogic = new NaplozasLogic(validator, co);
|
|
|
|
if (IsNaplozhatZarastolFuggetlenul(naplozasLogic.GetModel.OraAdat.OraKezdete.Date, naplozasLogic.GetModel.OraAdat.OsztalyCsoportId))
|
|
{
|
|
var orarendiOraHelper = new CsengetesiRendOrakHelper(ConnectionTypeExtensions.GetActiveSessionConnectionType());
|
|
if (model.TanoraAdatokRogzites.CsengetesiRendID.HasValue && !model.TanoraMuveletek.IsTanoranKivuli)
|
|
{
|
|
var csengrendOraId = orarendiOraHelper.GetCsengetesiRendOraId(model.TanoraAdatokRogzites.CsengetesiRendID.Value, model.TanoraAdatokRogzites.Oraszam.Value);
|
|
if (!csengrendOraId.HasValue)
|
|
{
|
|
throw new KretaError(OrarendResource.CsengetesiRendhezNincsCsengetesiOra);
|
|
}
|
|
model.TanoraAdatokRogzites.CsengetesiRendOraId = csengrendOraId;
|
|
}
|
|
|
|
LicenceHelper.LicenceWait(ClaimData.LicenceDatum);
|
|
saveResult = naplozasLogic.SaveNaplozas(_fileServiceHelper, _coreApiClient);
|
|
}
|
|
}
|
|
catch (KretaError ke)
|
|
{
|
|
ModelState.AddModelError(ErrorResource.Hiba, ke.Message);
|
|
}
|
|
catch (ValidationException ve)
|
|
{
|
|
ModelState.AddModelError(ErrorResource.Hiba, ve.Message);
|
|
}
|
|
catch (BlException e)
|
|
{
|
|
throw new StatusError(HttpStatusCode.BadRequest, e.Message);
|
|
}
|
|
|
|
if (ModelState.IsValid)
|
|
{
|
|
ClaimData.NemNaplozottTanorakCount = ClaimData.SetNemNaplozottTanorakCount();
|
|
return Request.CreateResponse(HttpStatusCode.OK, new { saveResult.TanitasiOraId, saveResult.HazifeladatId, saveResult.DKTHiba });
|
|
}
|
|
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
|
}
|
|
|
|
[NonAction]
|
|
public HttpResponseMessage SaveNemMegtartottNaplozas(TanoraNaplozasRogzites model, int? szervezetTipusId = null)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
var naploValidacioParameters = new NaploValidacioParameters(model.TanoraMuveletek.CalendarModel.Start, ConnectionTypeExtensions.GetSessionConnectionType(), ClaimData.FelhasznaloSzerepkor);
|
|
var validator = new NaploValidacio(naploValidacioParameters);
|
|
|
|
var co = new NaplozasCo();
|
|
model.ConvertTo(co, model.TanoraMuveletek.NaplozasDatum);
|
|
var naplozasLogic = new NaplozasLogic(validator, co);
|
|
|
|
if (IsNaplozhatZarastolFuggetlenul(naplozasLogic.GetModel.OraAdat.OraKezdete.Date, naplozasLogic.GetModel.OraAdat.OsztalyCsoportId))
|
|
{
|
|
LicenceHelper.LicenceWait(ClaimData.LicenceDatum);
|
|
naplozasLogic.SaveNemMegtartottNaplozas(_fileServiceHelper, _coreApiClient);
|
|
}
|
|
|
|
ClaimData.NemNaplozottTanorakCount = ClaimData.SetNemNaplozottTanorakCount();
|
|
return new HttpResponseMessage(HttpStatusCode.OK);
|
|
}
|
|
|
|
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
|
|
}
|
|
|
|
[NonAction]
|
|
public IHttpActionResult DeleteTanora(TanoraMuveletek pram, int? szervezetTipusId = null)
|
|
{
|
|
if (!Authorization.IsValidTanitasiOra(pram.CalendarModel.EventId))
|
|
{
|
|
throw new StatusError(HttpStatusCode.Forbidden, ErrorResource.AFelhasznalonakNincsMegfeleloJogosultsagaAFunkcioHasznalatahoz);
|
|
}
|
|
|
|
try
|
|
{
|
|
LicenceHelper.LicenceWait(ClaimData.LicenceDatum);
|
|
var helper = new TanoraHelper(ConnectionTypeExtensions.GetActiveSessionConnectionType());
|
|
|
|
helper.NaplozasTorlese(pram.CalendarModel.EventId, true);
|
|
|
|
ClaimData.NemNaplozottTanorakCount = ClaimData.SetNemNaplozottTanorakCount();
|
|
return Json(new { Title = CommonResource.Siker, Text = CommonResource.SikeresTorles });
|
|
}
|
|
catch (KretaError e)
|
|
{
|
|
return Json(new { Title = CommonResource.BiztosanTorli, Text = e.Message, TanoraId = pram.CalendarModel.EventId });
|
|
}
|
|
catch (KretaMissingTanoraException e)
|
|
{
|
|
throw new StatusError(HttpStatusCode.BadRequest, ErrorResource.HibaTortentAMuveletSoran) { UnHandledException = e };
|
|
}
|
|
catch (BlException e)
|
|
{
|
|
throw new StatusError(HttpStatusCode.BadRequest, e.Message) { UnHandledException = e };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new StatusError(HttpStatusCode.InternalServerError, ErrorResource.HibaTortentAMuveletSoran) { UnHandledException = ex };
|
|
}
|
|
}
|
|
|
|
public bool IsNaplozhatZarastolFuggetlenul(DateTime date, int? osztalyId)
|
|
{
|
|
var naplozarasLogic = new NaplozarasLogic(ConnectionTypeExtensions.GetSessionConnectionType());
|
|
return naplozarasLogic.IsNaplozhatZarastolFuggetlenul(date, osztalyId);
|
|
}
|
|
|
|
public int GetNemNaplozottTanorakCount()
|
|
{
|
|
return ClaimData.NemNaplozottTanorakCount;
|
|
}
|
|
|
|
|
|
private bool IsTeremBefogadokepessegeKissebbMintAzOsztalyCsoportLetszama(SystemSettingsHelper systemSettingsHelper, TeremHelper teremHelper, int? teremId, int mulasztasokSzama)
|
|
{
|
|
if (teremId.HasValue) //Terem befogadóképesség ellenőrzése kell
|
|
{
|
|
var naplozasTeremBefogadokepesseg = systemSettingsHelper.GetSystemSettingValue<bool>(RendszerBeallitasTipusEnum.Naplozas_terem_befogadokepesseg);
|
|
|
|
if (naplozasTeremBefogadokepesseg)
|
|
{
|
|
var teremKapacitas = teremHelper.GetTeremKapacitasById(teremId.Value);
|
|
|
|
if (teremKapacitas < mulasztasokSzama)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|