kreta/KretaWeb/Areas/Feljegyzes/Models/KozossegiSzolgalatModel.cs
2024-03-13 00:33:46 +01:00

206 lines
9.5 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using Kreta.BusinessLogic.Classes;
using Kreta.BusinessLogic.HelperClasses;
using Kreta.Core;
using Kreta.Resources;
using Microsoft.Ajax.Utilities;
using ModelStateDictionary = System.Web.Http.ModelBinding.ModelStateDictionary;
namespace Kreta.Web.Areas.Feljegyzes.Models
{
public class KozossegiSzolgalatModel
{
#region Constructors
public KozossegiSzolgalatModel()
{
}
public KozossegiSzolgalatModel(KozossegiSzolgalatCo co)
{
Id = co.Id;
TanuloId = co.TanuloId;
IntervallumKezdete = co.IntervallumKezdete;
IntervallumVege = co.IntervallumVege;
TeljesitesiHelye = co.TeljesitesiHelye;
TeljesitesiHelyeNemet = co.TeljesitesiHelyeNemet;
TeljesitesiHelyeHorvat = co.TeljesitesiHelyeHorvat;
TeljesitesiHelyeRoman = co.TeljesitesiHelyeRoman;
TeljesitesiHelyeSzerb = co.TeljesitesiHelyeSzerb;
Oraszam = co.Oraszam;
KozossegiSzolgalatTipusa = co.KozossegiSzolgalatTipusa;
Megjegyzes = co.Megjegyzes;
MegjegyzesNemet = co.MegjegyzesNemet;
MegjegyzesHorvat = co.MegjegyzesHorvat;
MegjegyzesRoman = co.MegjegyzesRoman;
MegjegyzesSzerb = co.MegjegyzesSzerb;
RogzitesDatuma = co.RogzitesDatuma;
}
#endregion Constructors
#region Properties
public int? Id { get; set; }
public int FeljegyzoId { get; set; }
public int TanuloId { get; set; }
public int OsztalyCsoportId { get; set; }
public List<int> NemzetiDokumentumNyelvek { get; set; } = new List<int>();
[KretaRequired]
[DateRange(ErrorMessageResourceName = nameof(ErrorResource.IntervallumKezdeteNemErvenyes), ErrorMessageResourceType = typeof(ErrorResource))]
[Display(Name = nameof(FeljegyzesekResource.IntervallumKezdete), ResourceType = typeof(FeljegyzesekResource))]
public DateTime IntervallumKezdete { get; set; }
[KretaRequired]
[DateRange(ErrorMessageResourceName = nameof(ErrorResource.IntervallumVegeNemErvenyes), ErrorMessageResourceType = typeof(ErrorResource))]
[Display(Name = nameof(FeljegyzesekResource.IntervallumVege), ResourceType = typeof(FeljegyzesekResource))]
public DateTime IntervallumVege { get; set; }
[Display(Name = nameof(FeljegyzesekResource.IntezmenyNeve), ResourceType = typeof(FeljegyzesekResource))]
[KretaRequired]
[MaxLength(255, ErrorMessageResourceName = nameof(CommonResource.MaxLengthValidation), ErrorMessageResourceType = typeof(CommonResource))]
public string TeljesitesiHelye { get; set; }
[Display(Name = nameof(FeljegyzesekResource.IntezmenyNeveNemet), ResourceType = typeof(FeljegyzesekResource))]
[MaxLength(255, ErrorMessageResourceName = nameof(CommonResource.MaxLengthValidation), ErrorMessageResourceType = typeof(CommonResource))]
public string TeljesitesiHelyeNemet { get; set; }
[Display(Name = nameof(FeljegyzesekResource.IntezmenyNeveHorvat), ResourceType = typeof(FeljegyzesekResource))]
[MaxLength(255, ErrorMessageResourceName = nameof(CommonResource.MaxLengthValidation), ErrorMessageResourceType = typeof(CommonResource))]
public string TeljesitesiHelyeHorvat { get; set; }
[Display(Name = nameof(FeljegyzesekResource.IntezmenyNeveRoman), ResourceType = typeof(FeljegyzesekResource))]
[MaxLength(255, ErrorMessageResourceName = nameof(CommonResource.MaxLengthValidation), ErrorMessageResourceType = typeof(CommonResource))]
public string TeljesitesiHelyeRoman { get; set; }
[Display(Name = nameof(FeljegyzesekResource.IntezmenyNeveSzerb), ResourceType = typeof(FeljegyzesekResource))]
[MaxLength(255, ErrorMessageResourceName = nameof(CommonResource.MaxLengthValidation), ErrorMessageResourceType = typeof(CommonResource))]
public string TeljesitesiHelyeSzerb { get; set; }
[KretaRequired]
[Display(Name = nameof(FeljegyzesekResource.Oraszam), ResourceType = typeof(FeljegyzesekResource))]
public double? Oraszam { get; set; }
[Display(Name = nameof(FeljegyzesekResource.Megjegyzes), ResourceType = typeof(FeljegyzesekResource))]
[MaxLength(1000, ErrorMessageResourceName = nameof(CommonResource.MaxLengthValidation), ErrorMessageResourceType = typeof(CommonResource))]
public string Megjegyzes { get; set; }
[Display(Name = nameof(FeljegyzesekResource.MegjegyzesNemet), ResourceType = typeof(FeljegyzesekResource))]
[MaxLength(1000, ErrorMessageResourceName = nameof(CommonResource.MaxLengthValidation), ErrorMessageResourceType = typeof(CommonResource))]
public string MegjegyzesNemet { get; set; }
[Display(Name = nameof(FeljegyzesekResource.MegjegyzesHorvat), ResourceType = typeof(FeljegyzesekResource))]
[MaxLength(1000, ErrorMessageResourceName = nameof(CommonResource.MaxLengthValidation), ErrorMessageResourceType = typeof(CommonResource))]
public string MegjegyzesHorvat { get; set; }
[Display(Name = nameof(FeljegyzesekResource.MegjegyzesRoman), ResourceType = typeof(FeljegyzesekResource))]
[MaxLength(1000, ErrorMessageResourceName = nameof(CommonResource.MaxLengthValidation), ErrorMessageResourceType = typeof(CommonResource))]
public string MegjegyzesRoman { get; set; }
[Display(Name = nameof(FeljegyzesekResource.MegjegyzesSzerb), ResourceType = typeof(FeljegyzesekResource))]
[MaxLength(1000, ErrorMessageResourceName = nameof(CommonResource.MaxLengthValidation), ErrorMessageResourceType = typeof(CommonResource))]
public string MegjegyzesSzerb { get; set; }
[KretaRequired]
[Display(Name = nameof(FeljegyzesekResource.RogzitesDatuma), ResourceType = typeof(FeljegyzesekResource))]
public DateTime RogzitesDatuma { get; set; }
[KretaRequired]
[Display(Name = nameof(FeljegyzesekResource.Tevekenyseg), ResourceType = typeof(FeljegyzesekResource))]
public int? KozossegiSzolgalatTipusa { get; set; }
public List<SelectListItem> KozossegiSzolgalatTipusList { get; set; }
#endregion Properties
public ModelStateDictionary Validate()
{
var modelStateDictionary = new ModelStateDictionary();
var now = DateTime.Today;
if (Oraszam > 50)
{
modelStateDictionary.AddModelError(nameof(Oraszam), ErrorResource.OraszamEgyes50Koze);
}
if (IntervallumVege > now)
{
modelStateDictionary.AddModelError(nameof(IntervallumVege), FeljegyzesekResource.IntervallumVegeNagyobbMintAMaiNap);
}
if (IntervallumKezdete > IntervallumVege)
{
modelStateDictionary.AddModelError(nameof(IntervallumKezdete), FeljegyzesekResource.IntervallumKezdeteNagyobbMintAVege);
}
if (TeljesitesiHelye.IsNullOrWhiteSpace())
{
modelStateDictionary.AddModelError(nameof(TeljesitesiHelye), string.Format(CommonResource.Required, $"\"{FeljegyzesekResource.IntezmenyNeve}\""));
}
if (!Oraszam.HasValue)
{
modelStateDictionary.AddModelError(nameof(Oraszam), string.Format(CommonResource.Required, $"\"{FeljegyzesekResource.Oraszam}\""));
}
else
{
var oraszam = Oraszam.Value;
if (oraszam < 1)
{
modelStateDictionary.AddModelError(nameof(Oraszam), FeljegyzesekResource.AzOraszamNemLehetKisebb1);
}
}
if (!KozossegiSzolgalatTipusa.IsEntityId())
{
modelStateDictionary.AddModelError(nameof(KozossegiSzolgalatTipusa), string.Format(CommonResource.Required, $"\"{FeljegyzesekResource.Tevekenyseg}\""));
}
if (RogzitesDatuma < IntervallumKezdete)
{
modelStateDictionary.AddModelError(nameof(RogzitesDatuma), FeljegyzesekResource.RogzitesDatumaNemLehetNagyobbMintAzIntervallumKedete);
}
return modelStateDictionary;
}
public KozossegiSzolgalatCo ToCo()
{
var result = new KozossegiSzolgalatCo
{
Id = Id,
TanuloId = TanuloId,
IntervallumKezdete = IntervallumKezdete,
IntervallumVege = IntervallumVege,
Megjegyzes = Megjegyzes,
MegjegyzesNemet = MegjegyzesNemet,
MegjegyzesHorvat = MegjegyzesHorvat,
MegjegyzesRoman = MegjegyzesRoman,
MegjegyzesSzerb = MegjegyzesSzerb,
//NOTE: Validáció miatt nem lehet null az Oraszam!!!
Oraszam = Oraszam.Value,
TeljesitesiHelye = TeljesitesiHelye,
TeljesitesiHelyeNemet = TeljesitesiHelyeNemet,
TeljesitesiHelyeHorvat = TeljesitesiHelyeHorvat,
TeljesitesiHelyeRoman = TeljesitesiHelyeRoman,
TeljesitesiHelyeSzerb = TeljesitesiHelyeSzerb,
FeljegyzoId = FeljegyzoId,
//NOTE: Validáció miatt nem lehet null a KozossegiSzolgalatTipusa!!!
KozossegiSzolgalatTipusa = KozossegiSzolgalatTipusa.Value,
RogzitesDatuma = RogzitesDatuma
};
return result;
}
}
}