public ValidationError Execute(Family family, NonBlockingValidationContext context) { if (family != null) { var child = context.GetParentEntity <Child>(); // Enrollments for children living with foster families // are exempt from family determination validations if (child != null && !child.Foster) { var enrollment = context.GetParentEntity <Enrollment>(); if (enrollment != null) { var fundings = enrollment.Fundings ?? _fundings.GetFundingsByEnrollmentId(enrollment.Id); // If enrollment is funded if (fundings.Any(f => f.Source == FundingSource.CDC)) { // most recent determination must be < 1 year old from today var compareDate = DateTime.Now.Date; // unless validating in the context of a report, // in which case determination date must be < 1 year from // end of report's reporting period var report = context.GetParentEntity <CdcReport>(); if (report != null) { compareDate = report.ReportingPeriod?.PeriodEnd ?? _reportingPeriods.GetById(report.ReportingPeriodId).PeriodEnd; } var mostRecentDetermination = (family.Determinations ?? _determinations.GetDeterminationsByFamilyId(family.Id)) .OrderByDescending(d => d.DeterminationDate) .FirstOrDefault(); if (mostRecentDetermination != null) { if (mostRecentDetermination.DeterminationDate.HasValue && mostRecentDetermination.DeterminationDate < compareDate.AddYears(-1) ) { return(new ValidationError( field: "Determinations", message: "Annual income determinations is due" )); } } } } } } return(null); }
public ValidationError Execute(FamilyDetermination determination, NonBlockingValidationContext context) { var enrollment = context.GetParentEntity <Enrollment>(); if (enrollment == null) { return(null); } var fundings = enrollment.Fundings ?? _fundings.GetFundingsByEnrollmentId(enrollment.Id); if (fundings.Any(f => f.Source == FundingSource.CDC)) { // Generally, DeterminationDate must be < 1 year from today var compareDate = DateTime.Now.Date; // However, if validating in the context of report enrollments, // determination date must be < 1 year from end of reporting period var report = context.GetParentEntity <CdcReport>(); if (report != null) { compareDate = report.ReportingPeriod != null ? report.ReportingPeriod.PeriodEnd : _reportingPeriods.GetById(report.ReportingPeriodId).PeriodEnd; } if (determination.DeterminationDate < compareDate.AddYears(-1)) { return(new ValidationError( field: "DeterminationDate", message: "Annual income determination is due" )); } } return(null); }
public ValidationError Execute(Family family, NonBlockingValidationContext context) { var child = context.GetParentEntity <Child>(); // Enrollments for children living with foster families // are exempt from family determination validations if (child != null && !child.Foster && family != null) { var determinations = family.Determinations ?? _determinations.GetDeterminationsByFamilyId(family.Id); ValidateSubObject(determinations, family); if (determinations.Any(det => det.ValidationErrors.Count > 0)) { return(new ValidationError( field: "Determinations", message: "Determinations has validation error", isSubObjectValidation: true )); } } return(null); }