Refactor Api-Client
Add Exceptionhandler, AlertService JSON-Converter AppSettings via DI Reformat Code
This commit is contained in:
31
Jugenddienst Stunden/Validators/HoursValidator.cs
Normal file
31
Jugenddienst Stunden/Validators/HoursValidator.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Jugenddienst_Stunden.Infrastructure;
|
||||
using Jugenddienst_Stunden.Types;
|
||||
|
||||
namespace Jugenddienst_Stunden.Validators;
|
||||
|
||||
internal interface IHoursValidator {
|
||||
void Validate(DayTime item, Settings settings);
|
||||
}
|
||||
|
||||
internal sealed class HoursValidator : IHoursValidator {
|
||||
public void Validate(DayTime item, Settings settings) {
|
||||
if (item.FreistellungAktiv is null && item.TimeSpanVon == item.TimeSpanBis)
|
||||
throw new ValidationException("Beginn und Ende sind gleich");
|
||||
|
||||
if (item.TimeSpanBis < item.TimeSpanVon)
|
||||
throw new ValidationException("Ende ist vor Beginn");
|
||||
|
||||
if (settings.GemeindeAktivSet && item.GemeindeAktiv is null)
|
||||
throw new ValidationException("Gemeinde nicht gewählt");
|
||||
|
||||
if (settings.ProjektAktivSet && item.ProjektAktiv is null)
|
||||
throw new ValidationException("Projekt nicht gewählt");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(item.Description)) {
|
||||
if (item.FreistellungAktiv?.Name is string name && !string.IsNullOrWhiteSpace(name))
|
||||
item.Description = name;
|
||||
else
|
||||
throw new ValidationException("Keine Beschreibung");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user