Esempio n. 1
0
 public GetOverlappingApprenticeshipsQueryHandler(IValidationApi validationApi)
 {
     if (validationApi == null)
     {
         throw new ArgumentException(nameof(validationApi));
     }
     _validationApi = validationApi;
 }
        public EditApprenticeshipStopDateViewModelValidator(ICurrentDateTime currentDateTime, IAcademicYearDateProvider academicYearDateProvider, IValidationApi validationApi, IHashingService hashingService)
        {
            _currentDateTime = currentDateTime;
            _validationApi   = validationApi;
            _hashingService  = hashingService;

            RuleFor(r => r.NewStopDate)
            .Cascade(CascadeMode.StopOnFirstFailure)
            .NotNull().WithMessage("Enter the stop date for this apprenticeship")
            .Must(d => d.DateTime.HasValue).WithMessage("Enter the stop date for this apprenticeship")
            .Must(d => d.DateTime <= new DateTime(_currentDateTime.Now.Year, _currentDateTime.Now.Month, 1)).WithMessage("The stop date cannot be in the future")
            .Must((model, newStopDate) => newStopDate.DateTime >= new DateTime(model.ApprenticeshipStartDate.Year, model.ApprenticeshipStartDate.Month, 1)).WithMessage("The stop month cannot be before the apprenticeship started")
            .Must((model, newStopDate) => newStopDate.DateTime != model.CurrentStopDate).WithMessage("Enter a date that is different to the current stopped date")
            .MustAsync(NotOverlap).WithMessage("The date overlaps with existing dates for the same apprentice.");
        }
 public GetOverlappingApprenticeshipsQueryHandler(IValidationApi validationApi)
 {
     _validationApi = validationApi;
 }