Skip to content

Commit

Permalink
Merge pull request #285 from bcgov/S_ProdSupport_LicenceValidattion
Browse files Browse the repository at this point in the history
Funding validations
  • Loading branch information
PhillipECC authored Dec 12, 2024
2 parents de11d75 + 36c2a1f commit 471c8ac
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ public async Task<bool> CalculateAsync()
.NextValidator(new MustHaveValidApplicationStatusRule())
.NextValidator(new MustHaveValidOwnershipTypeRule())
.NextValidator(new MustHaveValidLicenceRule())
.NextValidator(new MustHaveAtLeastOneValidLicenceDetailRule());
.NextValidator(new MustHaveAtLeastOneValidLicenceDetailRule())
.NextValidator(new MustHaveAtLeastOneOperationalSpaceRule())
.NextValidator(new MustHaveWeeksInOperationRule())
.NextValidator(new MustHaveHoursOfOperationRule())
.NextValidator(new MustHaveDaysOfWeekRule());
try
{
fundingRules.Validate(_funding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,126 @@ public bool Validate(Funding funding)
return true;
}

public IFundingValidator<Funding> NextValidator(IFundingValidator<Funding>? next)
{
_next = next;
return next;
}
}

public class MustHaveAtLeastOneOperationalSpaceRule : IFundingValidator<Funding>
{
private IFundingValidator<Funding>? _next;

public bool Validate(Funding funding)
{
var operationalSpaces = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld
.ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode
== ofm_licence_detail_StatusCode.Active && (licDetail.ofm_operational_spaces
< 1 || licDetail.ofm_operational_spaces == null)).Count();

if (operationalSpaces > 0)
{
throw new ValidationException(
new ValidationResult("The Service Delivery Details must have valid Operational Spaces.", ["Service Delivery Details"]), null, null);
}

_next?.Validate(funding);

return true;
}

public IFundingValidator<Funding> NextValidator(IFundingValidator<Funding>? next)
{
_next = next;
return next;
}
}

public class MustHaveWeeksInOperationRule : IFundingValidator<Funding>
{
private IFundingValidator<Funding>? _next;

public bool Validate(Funding funding)
{
var weeksInOperation = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld
.ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode
== ofm_licence_detail_StatusCode.Active && (licDetail.ofm_weeks_in_operation
< 1 || licDetail.ofm_weeks_in_operation == null)).Count();

if (weeksInOperation > 0)
{
throw new ValidationException(
new ValidationResult("The Service Delivery Details must have valid Weeks in Operation.", ["Service Delivery Details"]), null, null);
}

_next?.Validate(funding);

return true;
}

public IFundingValidator<Funding> NextValidator(IFundingValidator<Funding>? next)
{
_next = next;
return next;
}
}

public class MustHaveHoursOfOperationRule : IFundingValidator<Funding>
{
private IFundingValidator<Funding>? _next;

public bool Validate(Funding funding)
{
var operationHoursFrom = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld
.ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode
== ofm_licence_detail_StatusCode.Active && licDetail.ofm_operation_hours_from
== null).Count();
var operationHoursTo = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld
.ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode
== ofm_licence_detail_StatusCode.Active && licDetail.ofm_operation_hours_to
== null).Count();

if (operationHoursFrom > 0 || operationHoursTo > 0)
{
throw new ValidationException(
new ValidationResult("The Service Delivery Details must have valid Operation Hours.", ["Service Delivery Details"]), null, null);
}

_next?.Validate(funding);

return true;
}

public IFundingValidator<Funding> NextValidator(IFundingValidator<Funding>? next)
{
_next = next;
return next;
}
}

public class MustHaveDaysOfWeekRule : IFundingValidator<Funding>
{
private IFundingValidator<Funding>? _next;

public bool Validate(Funding funding)
{
var weekDays = funding.ofm_facility?.ofm_facility_licence?.SelectMany(ld => ld
.ofm_licence_licencedetail!).Where(licDetail => licDetail.statuscode
== ofm_licence_detail_StatusCode.Active && licDetail.ofm_week_days
== null).Count();

if (weekDays > 0)
{
throw new ValidationException(
new ValidationResult("The Service Delivery Details must have valid Week Days when the ChildCare is operating.", ["Service Delivery Details"]), null, null);
}

_next?.Validate(funding);

return true;
}

public IFundingValidator<Funding> NextValidator(IFundingValidator<Funding>? next)
{
_next = next;
Expand Down

0 comments on commit 471c8ac

Please sign in to comment.