126 lines
4.7 KiB
C#
126 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using Kreta.BusinessLogic.Logic.Naplozas;
|
|
using Kreta.Enums;
|
|
using Kreta.Resources;
|
|
|
|
namespace Kreta.BusinessLogic.Classes.MobileApi.Naplo.V2.Co.Post.Naplozas
|
|
{
|
|
public class OraNaplozasRequestCo : IValidatableObject
|
|
{
|
|
public DateTime Datum { get; set; }
|
|
|
|
public string Hazifeladat { get; set; }
|
|
|
|
public DateTime? HazifeladatHatarido { get; set; }
|
|
|
|
public int? HazifeladatId { get; set; }
|
|
|
|
public bool IsElmaradt { get; set; }
|
|
|
|
public int MobilId { get; set; }
|
|
|
|
public int? OrarendiOraId { get; set; }
|
|
|
|
public DateTime RogzitesDatum { get; set; }
|
|
|
|
public int? TanitasiOraId { get; set; }
|
|
|
|
public List<TanuloForOraNaplozasRequestCo> TanuloLista { get; set; }
|
|
|
|
public string Tema { get; set; }
|
|
|
|
public int? CsatolmanyId { get; set; }
|
|
|
|
public void ConvertTo(NaplozasMobilCo co)
|
|
{
|
|
co.OraAdat.Datum = Datum;
|
|
co.OraAdat.IsElmaradt = IsElmaradt;
|
|
co.OraAdat.Tema = Tema;
|
|
co.OraAdat.OrarendiOraId = OrarendiOraId;
|
|
co.OraAdat.TanitasiOraId = TanitasiOraId;
|
|
co.Hazifeladat.Id = HazifeladatId;
|
|
co.Hazifeladat.Szoveg = Hazifeladat;
|
|
co.Hazifeladat.Hatarido = HazifeladatHatarido;
|
|
co.Hazifeladat.CsatolmanyId = CsatolmanyId;
|
|
co.OraAdat.RogzitesDatuma = RogzitesDatum;
|
|
foreach (var tanulo in TanuloLista)
|
|
{
|
|
var tanuloMulasztas = new NaplozasMobilCo.MulasztasModel
|
|
{
|
|
TanuloId = tanulo.Id,
|
|
MulasztasTipus = tanulo.Mulasztas.Tipus.Id,
|
|
Keses = tanulo.Mulasztas.Keses
|
|
};
|
|
|
|
foreach (var feljegyzesTipus in tanulo.FeljegyzesTipusLista)
|
|
{
|
|
switch (feljegyzesTipus.Id)
|
|
{
|
|
case (int)EsemenyTipusEnum.HaziFeladatHiany:
|
|
tanuloMulasztas.HazifeladatHiany = true;
|
|
break;
|
|
case (int)EsemenyTipusEnum.Felszereleshiany:
|
|
tanuloMulasztas.FelszerelesHiany = true;
|
|
break;
|
|
case (int)EsemenyTipusEnum.Dicseret:
|
|
tanuloMulasztas.TanoraiDicseret = true;
|
|
break;
|
|
case (int)EsemenyTipusEnum.SzakmaiMentessegNemHivatalos:
|
|
tanuloMulasztas.Felmentes = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
co.MulasztasList.Add(tanuloMulasztas);
|
|
}
|
|
}
|
|
|
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
|
{
|
|
if (HazifeladatHatarido < Datum.Date.AddDays(1))
|
|
{
|
|
yield return new ValidationResult(ErrorResource.HazifeladatNemrogzithetoHataridoKorabbiMintAzOraDatuma);
|
|
}
|
|
|
|
if (HazifeladatHatarido < DateTime.Today.AddDays(1))
|
|
{
|
|
yield return new ValidationResult(ErrorResource.HazifeladatNemrogzithetoHataridoKorabbiMintAHolnapiNap);
|
|
}
|
|
|
|
if (HazifeladatId.HasValue && string.IsNullOrWhiteSpace(Hazifeladat))
|
|
{
|
|
yield return new ValidationResult(OrarendResource.HazifeladatSzovegKotelezo);
|
|
}
|
|
|
|
var occurrenceNumberByPrimaryKey = new Dictionary<int, int>();
|
|
|
|
foreach (var tanulo in TanuloLista)
|
|
{
|
|
if (occurrenceNumberByPrimaryKey.ContainsKey(tanulo.Id))
|
|
{
|
|
occurrenceNumberByPrimaryKey[tanulo.Id]++;
|
|
}
|
|
else
|
|
{
|
|
occurrenceNumberByPrimaryKey.Add(tanulo.Id, 1);
|
|
}
|
|
|
|
//TODO: késés értékének felső határát is validálni (nagyobb átalakítás)
|
|
if (tanulo.Mulasztas.Tipus.Id == (int)MulasztasTipusEnum.keses && tanulo.Mulasztas.Keses <= 0)
|
|
{
|
|
yield return new ValidationResult(string.Format(ErrorResource.AKesesErtekeNemLehet0, tanulo.Mulasztas.Keses));
|
|
}
|
|
}
|
|
|
|
foreach (var occurrenceNumberByPrimaryKeyItem in occurrenceNumberByPrimaryKey)
|
|
{
|
|
if (occurrenceNumberByPrimaryKeyItem.Value > 1)
|
|
{
|
|
yield return new ValidationResult($"A tanuló többször szerepel: {nameof(TanuloForOraNaplozasRequestCo.Id)}={occurrenceNumberByPrimaryKeyItem.Key}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|