internal static IRuleBuilderInitial <Vacancy, Vacancy> TrainingMustBeActiveForStartDate(this IRuleBuilder <Vacancy, Vacancy> ruleBuilder, IApprenticeshipProgrammeProvider apprenticeshipProgrammesProvider)
        {
            return(ruleBuilder.CustomAsync(async(vacancy, context, cancellationToken) =>
            {
                if (!vacancy.StartDate.HasValue)
                {
                    var message = $"The start date must have a value.";
                    var failure = new ValidationFailure(string.Empty, message)
                    {
                        ErrorCode = ErrorCodes.TrainingExpiryDate,
                        CustomState = VacancyRuleSet.TrainingExpiryDate,
                        PropertyName = nameof(Vacancy.StartDate)
                    };
                    context.AddFailure(failure);
                }

                var allProgrammes = await apprenticeshipProgrammesProvider.GetApprenticeshipProgrammesAsync();

                var matchingProgramme = allProgrammes.SingleOrDefault(x => x.Id.Equals(vacancy.ProgrammeId, StringComparison.InvariantCultureIgnoreCase));

                if (matchingProgramme.EffectiveTo != null && matchingProgramme.EffectiveTo < vacancy.StartDate)
                {
                    var message = $"The start date must be before {matchingProgramme.EffectiveTo.Value.AsGdsDate()} when the apprenticeship training closes to new starters.";
                    var failure = new ValidationFailure(string.Empty, message)
                    {
                        ErrorCode = ErrorCodes.TrainingExpiryDate,
                        CustomState = VacancyRuleSet.TrainingExpiryDate,
                        PropertyName = nameof(Vacancy.StartDate)
                    };
                    context.AddFailure(failure);
                }
            }));
        }
Ejemplo n.º 2
0
        internal static IRuleBuilderInitial <Vacancy, Vacancy> TrainingMustBeActiveForStartDate(this IRuleBuilder <Vacancy, Vacancy> ruleBuilder, IApprenticeshipProgrammeProvider apprenticeshipProgrammesProvider)
        {
            return(ruleBuilder.CustomAsync(async(vacancy, context, cancellationToken) =>
            {
                var allProgrammes = await apprenticeshipProgrammesProvider.GetApprenticeshipProgrammesAsync();

                var matchingProgramme = allProgrammes.SingleOrDefault(x => x.Id.Equals(vacancy.ProgrammeId, StringComparison.InvariantCultureIgnoreCase));

                if (matchingProgramme.EffectiveTo != null && matchingProgramme.EffectiveTo < vacancy.StartDate)
                {
                    var failure = new ValidationFailure(string.Empty, $"The {matchingProgramme.Title} {matchingProgramme.ApprenticeshipType} is no longer available on the date selected. Choose other apprenticeship training or change the start date.")
                    {
                        ErrorCode = "26",
                        CustomState = VacancyRuleSet.TrainingExpiryDate
                    };
                    context.AddFailure(failure);
                }
            }));
        }
 public Task <IEnumerable <IApprenticeshipProgramme> > GetActiveApprenticeshipProgrammesAsync()
 {
     return(_apprenticeshipProgrammesProvider.GetApprenticeshipProgrammesAsync());
 }
        public FluentVacancyValidator(ITimeProvider timeProvider, IMinimumWageProvider minimumWageService, IApprenticeshipProgrammeProvider apprenticeshipProgrammesProvider, IQualificationsProvider qualificationsProvider, IHtmlSanitizerService htmlSanitizerService)
        {
            _timeProvider             = timeProvider;
            _minimumWageService       = minimumWageService;
            _qualificationsProvider   = qualificationsProvider;
            _apprenticeshipProgrammes = new Lazy <IEnumerable <IApprenticeshipProgramme> >(() => apprenticeshipProgrammesProvider.GetApprenticeshipProgrammesAsync().Result);
            _htmlSanitizerService     = htmlSanitizerService;

            SingleFieldValidations();

            CrossFieldValidations();
        }