Example #1
0
        public UpdateVacancyValidator(
            IVacancyRepository vacancyRepository,
            IComponentContext componentContext)
        {
            Guard.AgainstNullArgument(nameof(vacancyRepository), vacancyRepository);
            Guard.AgainstNullArgument(nameof(componentContext), componentContext);

            RuleFor(m => m.Vacancy).NotNull()
            .WithMessage(Messages.NotNull)
            .DependentRules(() =>
            {
                RuleFor(m => m.Vacancy.Id).NotNull()
                .WithMessage(Messages.NotNull)
                .DependentRules(() =>
                {
                    RuleFor(m => m.Vacancy.Id)
                    .MustAsync((id, token) => vacancyRepository.Exists(id.Value))
                    .WithMessage("Вакансии с id '{PropertyValue}' не существует.");

                    RuleFor(m => m.Vacancy)
                    .MustAsync(async(vacancy, token) =>
                               (await vacancyRepository.GetStatus(vacancy.Id.Value)) == VacancyStatusEntity.Draft)
                    .WithMessage("Для изменения вакансия должна быть черновиком.")

                    .MustAsync(async(vacancy, token) =>
                               (await vacancyRepository.Get(vacancy.Id.Value)).JobPositionId == vacancy.JobPositionId)
                    .WithMessage("Нельзя изменять должность вакансии.");
                    ;
                });

                RuleFor(m => m.Vacancy)
                .SetValidator(componentContext.Resolve <VacancyValidator>());
            });
        }
Example #2
0
 public CloseVacancyValidator(IVacancyRepository vacancyRepository)
 {
     RuleFor(m => m.VacancyId).NotNull()
     .WithMessage(Messages.NotNull)
     .DependentRules(() =>
     {
         RuleFor(m => m.VacancyId)
         .MustAsync(async(id, token) =>
                    (await vacancyRepository.GetStatus(id.Value)) == VacancyStatusEntity.Opened)
         .WithMessage("Для закрытия вакансия должна быть открыта.");
     });
 }
 public OpenVacancyValidator(IVacancyRepository vacancyRepository)
 {
     RuleFor(m => m.VacancyId).NotNull()
     .WithMessage(Messages.NotNull)
     .DependentRules(() =>
     {
         RuleFor(m => m.VacancyId)
         .MustAsync((id, token) => vacancyRepository.Exists(id.Value))
         .WithMessage("Вакансии с id '{PropertyValue}' не существует.")
         .MustAsync(async(id, token) =>
                    (await vacancyRepository.GetStatus(id.Value)) == VacancyStatusEntity.Draft)
         .WithMessage("Вакансия должна быть черновиком.");
     });
 }