/// <summary> /// If all apprenticeships share the same Funding Cap, this is it. /// If they have different funding caps, or there is no trainingprogram or apprenticeships, /// or there is not enough data to calculate the funding cap for each apprenticeship, this is null /// </summary> private int?CalculateCommonFundingCap() { if (TrainingProgramme == null || !Apprenticeships.Any()) { return(null); } if (!IsLinkedToChangeOfPartyRequest && Apprenticeships.Any(a => !a.StartDate.HasValue)) { return(null); } int firstFundingCap = IsLinkedToChangeOfPartyRequest ? TrainingProgramme.FundingCapOn(Apprenticeships.First().OriginalStartDate.Value) : TrainingProgramme.FundingCapOn(Apprenticeships.First().StartDate.Value); // check for magic 0, which means unable to calculate a funding cap (e.g. date out of bounds) if (firstFundingCap == 0) { return(null); } if (Apprenticeships.Skip(1).Any(a => TrainingProgramme.FundingCapOn(a.StartDate.Value) != firstFundingCap)) { return(null); } return(firstFundingCap); }
/// <summary> /// If all apprenticeships share the same Funding Cap, this is it. /// If they have different funding caps, or there is no trainingprogram or apprenticeships, /// or there is not enough data to calculate the funding cap for each apprenticeship, this is null /// </summary> private int?CalculateCommonFundingCap() { if (TrainingProgramme == null || !Apprenticeships.Any()) { return(null); } if (Apprenticeships.Any(a => !a.StartDate.HasValue)) { return(null); } var firstFundingCap = TrainingProgramme.FundingCapOn(Apprenticeships.First().StartDate.Value); // check for magic 0, which means unable to calculate a funding cap (e.g. date out of bounds) if (firstFundingCap == 0) { return(null); } if (Apprenticeships.Skip(1).Any(a => TrainingProgramme.FundingCapOn(a.StartDate.Value) != firstFundingCap)) { return(null); } return(firstFundingCap); }
private IEnumerable <DomainError> BuildUlnValidationFailures(DraftApprenticeshipDetails draftApprenticeshipDetails) { if (string.IsNullOrWhiteSpace(draftApprenticeshipDetails.Uln)) { yield break; } if (Apprenticeships.Any(a => a.Id != draftApprenticeshipDetails.Id && a.Uln == draftApprenticeshipDetails.Uln)) { yield return(new DomainError(nameof(draftApprenticeshipDetails.Uln), "The unique learner number has already been used for an apprentice in this cohort")); } }