using System; using System.Collections.Generic; using System.Linq; using BeWo.Data.Access; using BeWo.Data.Entities; using BeWo.Service.DCEntityMapper; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; using BS.Shared.Services; using BeWo.Service.Configuration; using BeWo.Data.Security; using SecurityUtils = BeWo.Service.Security.SecurityUtils; using BeWo.Service.ServiceImplementations; namespace BeWo.Service.Plugins { public class SupportConceptValidator { public virtual List ValidateSupportConcept(SupportConceptDC supportConcept) { var result = new List(); bool isNew = !supportConcept.SupportConceptOid.HasValue; // 1. Prüfe Datumsbereiche. Startdatum darf nicht größer als Enddatum sein bool containsDatumCheck = false; if (supportConcept.CostBearerRelations != null) { foreach (var c2s in supportConcept.CostBearerRelations) { if (!containsDatumCheck) { var val = CheckDate(c2s.StartDate, c2s.EndDate, c2s, null); if (val != null) { result.Add(val); containsDatumCheck = true; } if (c2s.ApprovalPeriodList != null) { foreach (var ap in c2s.ApprovalPeriodList) { if (!containsDatumCheck) { val = CheckDate(ap.StartDate, ap.EndDate, c2s, ap); if (val != null) { result.Add(val); containsDatumCheck = true; } } } } } } } return result; } private ValidationResultDC CheckDate(DateTime? start, DateTime? end, SupportConceptCostBearerRelDC c2s, SupportConceptApprovalPeriodDC scap) { if (start.HasValue && end.HasValue && start > end) { ValidationResultDC resultDc = new ValidationResultDC(); resultDc.Message = "Das Startdatum darf nicht größer als das Enddatum sein."; if (scap == null) { } resultDc.AllowSave = false; return resultDc; } return null; } public virtual List ValidateSupportConceptDeletion(long supportConceptOid) { var result = new List(); var os = new OperationsServiceImp(); var list = os.GetSupportConceptInfosForSupportConceptOid(supportConceptOid); if (list != null && list.Count > 0) { var containsServiceRecords = false; foreach (var info in list.Where(info => info.RecordedHours > 0)) { containsServiceRecords = true; } if (containsServiceRecords) { ValidationResultDC resultDc = new ValidationResultDC(); resultDc.Message = "Für den gewählten Hilfeplan wurden bereits Leistungen hinterlegt."; resultDc.AllowSave = true; result.Add(resultDc); } } return result; } } }