156 lines
6.8 KiB
C#
156 lines
6.8 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Kreta.BusinessLogic.HelperClasses;
|
|
using Kreta.BusinessLogic.Helpers;
|
|
using Kreta.Enums;
|
|
using Kreta.Enums.ManualEnums;
|
|
using Kreta.Framework;
|
|
using Kreta.KretaServer.SystemSettings;
|
|
using Kreta.Resources;
|
|
using Kreta.Web.Areas.Orarend.Models;
|
|
using Kreta.Web.Helpers;
|
|
using Kreta.Web.Security;
|
|
|
|
namespace Kreta.Web.Areas.Orarend.Logic
|
|
{
|
|
public class NemKotottMunkaidoLogic
|
|
{
|
|
public static System.Web.Http.ModelBinding.ModelStateDictionary CheckCustomValidation(System.Web.Http.ModelBinding.ModelStateDictionary ms, NemKotottMunkaidoModel model)
|
|
{
|
|
if (model.Veg.Value.TimeOfDay <= model.Kezdet.Value.TimeOfDay)
|
|
ms.AddModelError("NKMDateError", StringResourcesUtil.GetString(5274));
|
|
|
|
DateTime elsoNap;
|
|
TanevHelper helper = new TanevHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
|
var tanev = helper.GetTanevInfo();
|
|
elsoNap = tanev.OraFelvetelKezdete;
|
|
|
|
if (model.Kezdet < elsoNap)
|
|
ms.AddModelError("OraErvenyessegKezdete", StringResourcesUtil.GetString(3087));
|
|
|
|
if (model.ModositasiIdoszakTipus == (int)OraModositasiIdoszakTipus.EgyOra)
|
|
{
|
|
var naptariHetHelper = new NaptariHetHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
|
var hetirend = naptariHetHelper.GetNaptariHetHetirendByDate(model.Datum.Value);
|
|
if ((model.HetirendId.Value != (int)HetiRendTipusEnum.MindegyikHet)
|
|
&& (hetirend != model.HetirendId))
|
|
{
|
|
ms.AddModelError("HetirendId", ErrorResource.AKivalasztottNapNemAKivalasztottHetirendhezTartozik);
|
|
}
|
|
}
|
|
|
|
var nkmHelper = new NemKotottMunkaidoHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
|
bool hasTanarNemKotottMunkaidoUtkozes = nkmHelper.HasTanarNemKotottMunkaidoUtkozes(model.TanarId.Value, model.Kezdet.Value, model.Veg.Value, model.Id);
|
|
|
|
if (hasTanarNemKotottMunkaidoUtkozes)
|
|
{
|
|
ms.AddModelError("Kezdet", ErrorResource.ParhuzamosKotottMunkaidoFelveteleNemLehetseges);
|
|
}
|
|
|
|
return ms;
|
|
}
|
|
|
|
public static NemKotottMunkaidoCO ConvertModelToCO(NemKotottMunkaidoModel model)
|
|
{
|
|
var co = new NemKotottMunkaidoCO()
|
|
{
|
|
Id = model.Id,
|
|
GroupId = model.GroupId,
|
|
TorvenyKategoriaId = model.TorvenyKategoria.Value,
|
|
TanarId = model.TanarId.Value,
|
|
TulajId = model.TulajId,
|
|
Kezdete = model.Kezdet.Value,
|
|
Vege = model.Veg.Value,
|
|
Megtartott = model.isMegtartott,
|
|
Megjegyzes = model.Megjegyzes,
|
|
NaplozottMegjegyzes = model.NaplozottMegjegyzes,
|
|
HetirendId = model.HetirendId.Value
|
|
};
|
|
|
|
return co;
|
|
}
|
|
|
|
public static NemKotottMunkaidoModel ConvertModelFromCo(NemKotottMunkaidoCO co)
|
|
{
|
|
NemKotottMunkaidoModel model = new NemKotottMunkaidoModel()
|
|
{
|
|
Id = co.Id,
|
|
GroupId = co.GroupId,
|
|
TanarId = co.TanarId,
|
|
TulajId = co.TulajId,
|
|
Datum = co.Kezdete.Date,
|
|
Kezdet = co.Kezdete,
|
|
Veg = co.Vege,
|
|
TorvenyKategoria = co.TorvenyKategoriaId,
|
|
Megjegyzes = co.Megjegyzes,
|
|
HetirendId = co.HetirendId,
|
|
NaplozottMegjegyzes = co.NaplozottMegjegyzes,
|
|
isMegtartott = co.Megtartott,
|
|
isReadonly = co.isReadonly,
|
|
isTanarAltalTorolt = co.isTanarAltalTorolt
|
|
};
|
|
|
|
if (ClaimData.FelhasznaloId != co.TulajId)
|
|
{
|
|
model.isAdminRogzitette = true;
|
|
}
|
|
|
|
return model;
|
|
}
|
|
|
|
public static bool CheckUtkozesValidation(NemKotottMunkaidoModel model)
|
|
{
|
|
DateTime kezdetDatum, vegDatum;
|
|
GetKezdetVegDatumFomModel(model, out kezdetDatum, out vegDatum);
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
var orarendiOraHelper = new OrarendiOraHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
|
var result = orarendiOraHelper.NemkotottMunkaidoUtkozesEllenorzes(model.TanarId.Value, kezdetDatum, vegDatum, model.Datum.Value, model.HetirendId.Value, model.GroupId);
|
|
return result;
|
|
}
|
|
|
|
public static int GetNaplozottNemkotottMunkaidoSzamByGroupId(NemKotottMunkaidoModel model)
|
|
{
|
|
DateTime kezdetDatum, vegDatum;
|
|
GetKezdetVegDatumFomModel(model, out kezdetDatum, out vegDatum);
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
var orarendHelper = new OrarendHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
|
var result = orarendHelper.GetNemKotottMunkaIdo(kezdetDatum, vegDatum, model.GroupId).Where(x => x.Megtartott).Count();
|
|
return result;
|
|
}
|
|
|
|
private static void GetKezdetVegDatumFomModel(NemKotottMunkaidoModel model, out DateTime kezdetDatum, out DateTime vegDatum)
|
|
{
|
|
TanevCO tanevCO;
|
|
TanevHelper tanevHelper = new TanevHelper(ConnectionTypeExtensions.GetSessionConnectionType());
|
|
tanevCO = tanevHelper.GetTanevInfo();
|
|
|
|
kezdetDatum = OrarendiOraLogic.CreateLocalDateTimeBasedOnDateAndTime(model.Datum.Value, model.Kezdet.Value);
|
|
vegDatum = OrarendiOraLogic.CreateLocalDateTimeBasedOnDateAndTime(model.Datum.Value, model.Veg.Value);
|
|
switch (model.ModositasiIdoszakTipus)
|
|
{
|
|
case (int)OraModositasiIdoszakTipus.TeljesIdoszak:
|
|
kezdetDatum = tanevCO.OraFelvetelKezdete.Date.AddHours(kezdetDatum.Hour).AddMinutes(kezdetDatum.Minute);
|
|
vegDatum = tanevCO.UtolsoTanitasiNap.Date.AddHours(vegDatum.Hour).AddMinutes(vegDatum.Minute);
|
|
break;
|
|
case (int)OraModositasiIdoszakTipus.AdottNaptol:
|
|
vegDatum = tanevCO.UtolsoTanitasiNap.Date.AddHours(vegDatum.Hour).AddMinutes(vegDatum.Minute);
|
|
break;
|
|
case (int)OraModositasiIdoszakTipus.AdottNapig:
|
|
kezdetDatum = tanevCO.OraFelvetelKezdete.Date.AddHours(kezdetDatum.Hour).AddMinutes(kezdetDatum.Minute);
|
|
break;
|
|
case (int)OraModositasiIdoszakTipus.EgyOra:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public static int GetTevekenysegUtkozesSystemSetting()
|
|
{
|
|
return SystemSettingsManager.GetSystemSettingValue<int>(RendszerBeallitasTipusEnum.Napirend_felvitelel_utkozes_figyeles, ClaimData.IntezmenyAzonosito, ClaimData.SelectedTanevID.Value);
|
|
}
|
|
}
|
|
}
|