using System; using System.Net; using System.Net.Http; using System.Web.Http; using Kreta.BusinessLogic.Helpers; using Kreta.Core.Exceptions; using Kreta.Enums.ManualEnums; using Kreta.Framework; using Kreta.Resources; using Kreta.Web.Areas.Orarend.Logic; 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 BaseAdminOsztalyOrarendApiController : ApiController { [HttpPost] [ApiValidateAjaxAntiForgeryToken] public HttpResponseMessage SaveOrarendiOra(OrarendiOraModel model) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } OrarendiOraLogic.SetOraKezdetekAndOraVegek(model); var customModelState = OrarendiOraLogic.CheckCustomValidation(ModelState, model); if (!customModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, customModelState); } try { var orarendiOraHelper = new OrarendiOraHelper(ConnectionTypeExtensions.GetSessionConnectionType()); orarendiOraHelper.CheckUtkozesValidationAndSaveOrUpdateOrarendiOrak(OrarendiOraLogic.SetOraValidationCoFromOrarendiOraModel(model), ClaimData.FelhasznaloId); return new HttpResponseMessage(HttpStatusCode.OK); } catch (BlException ex) { throw new StatusError(HttpStatusCode.BadRequest, ex.Message); } throw new StatusError(HttpStatusCode.BadRequest, OrarendResource.AzOrarendiOratNemLehetModositaniMertMarTartozikHozzaNaplozottOra); } [HttpPost] [ApiValidateAjaxAntiForgeryToken] public HttpResponseMessage PreValidationOrarendiOra(OrarendiOraModel model) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } OrarendiOraLogic.SetOraKezdetekAndOraVegek(model); var customModelState = OrarendiOraLogic.CheckCustomValidation(ModelState, model); if (!customModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, customModelState); } var utkozesValidationMsg = OrarendiOraLogic.CheckUtkozesValidation(OrarendiOraLogic.SetOraValidationCoFromOrarendiOraModel(model), !model.ID.HasValue ? "OrarendiOrak.Save();" : "OrarendiOrak.ModConfirmSave();", isPrevalidation: true); if (utkozesValidationMsg.ErrorMsg.Length > 0) { throw new StatusError(HttpStatusCode.BadRequest, utkozesValidationMsg.ErrorMsg); } if (utkozesValidationMsg.Msg.Length > 0) { throw new StatusError(CustomHTTPStatusEnum.WarningMegszakitas, string.Empty) { Json = utkozesValidationMsg }; } return new HttpResponseMessage(HttpStatusCode.OK); } [HttpPost] [ApiValidateAjaxAntiForgeryToken] public bool HasHazifeladatOrHelyettesitesOrSzamonkeresForOrarendiOra(OrarendiOraModel model) { model.OraKezdete = OrarendiOraLogic.CreateLocalDateTimeBasedOnDateAndTime(model.OraErvenyessegVege.Value, model.OraKezdete.Value); model.OraVege = OrarendiOraLogic.CreateLocalDateTimeBasedOnDateAndTime(model.OraErvenyessegVege.Value, model.OraVege.Value); return new OrarendiOraHelper(ConnectionTypeExtensions.GetSessionConnectionType()).HasHazifeladatOrHelyettesitesOrSzamonkeresForOrarendiOra(OrarendiOraLogic.SetOraValidationCoFromOrarendiOraModel(model)); } [HttpPost] [ApiValidateAjaxAntiForgeryToken] public bool HasHazifeladatOrHelyettesitesOrSzamonkeresNotInIdoszak(OrarendiOraModel model) { model.OraKezdete = OrarendiOraLogic.CreateLocalDateTimeBasedOnDateAndTime(model.OraErvenyessegVege.Value, model.OraKezdete.Value); model.OraVege = OrarendiOraLogic.CreateLocalDateTimeBasedOnDateAndTime(model.OraErvenyessegVege.Value, model.OraVege.Value); return new OrarendiOraHelper(ConnectionTypeExtensions.GetSessionConnectionType()).HasHazifeladatOrHelyettesitesOrSzamonkeresNotInIdoszak(OrarendiOraLogic.SetOraValidationCoFromOrarendiOraModel(model)); } [HttpGet] public bool IsOrarendiNap(DateTime date) { var tanevrendHelper = new TanevrendHelper(ConnectionTypeExtensions.GetSessionConnectionType()); bool isOrarendiNap = tanevrendHelper.IsOrarendiNap(date, null); return isOrarendiNap; } [HttpGet] public bool HasTanitasiNap(DateTime date) { var tanevrendHelper = new TanevrendHelper(ConnectionTypeExtensions.GetSessionConnectionType()); bool isOrarendiNap = tanevrendHelper.IsOrarendiNap(date, null); if (isOrarendiNap) { return true; } return tanevrendHelper.HasTanitasiNap(date); } [HttpGet] public int GetOsztalyCsoportTerem(int? osztalyCsoportId) { if (osztalyCsoportId > 0) { return new OsztalyCsoportHelper(ConnectionTypeExtensions.GetSessionConnectionType()).GetOsztalyCsoportTeremId(osztalyCsoportId.Value); } return 0; } [HttpPost] [ApiValidateAjaxAntiForgeryToken] public HttpResponseMessage DeleteOrarendiOra(OrarendiOraModel model) { var orarendiOraHelper = new OrarendiOraHelper(ConnectionTypeExtensions.GetSessionConnectionType()); bool torlesSikeres = orarendiOraHelper.DeletOrarendiOra(model.ID.Value, model.ModositasiIdoszakTipus, model.ModificationDate); if (torlesSikeres) { return new HttpResponseMessage(HttpStatusCode.OK); } throw new StatusError(HttpStatusCode.BadRequest, StringResourcesUtil.GetString(4519)); } } }