Exemplo n.º 1
0
        internal static void AddServerCommonRules(this AbstractValidator <VacancyDatesViewModel> validator)
        {
            validator.RuleFor(x => x.ClosingDate)
            .SetValidator(new DateViewModelClientValidator());

            validator.RuleFor(x => x.ClosingDate)
            .Must(Common.BeValidDate)
            .WithMessage(VacancyViewModelMessages.ClosingDate.RequiredErrorText);

            validator.RuleFor(x => x.ClosingDate)
            .Must(Common.BeOneDayInTheFuture)
            .WithMessage(VacancyViewModelMessages.ClosingDate.AfterTodayErrorText)
            .When(IsNewVacancy);

            validator.RuleFor(x => x.ClosingDate)
            .Must(Common.BeTodayOrInTheFuture)
            .WithMessage(VacancyViewModelMessages.ClosingDate.TodayOrInTheFutureErrorText)
            .When(x => !IsNewVacancy(x));

            validator.RuleFor(x => x.PossibleStartDate)
            .Must(Common.BeValidDate)
            .WithMessage(VacancyViewModelMessages.PossibleStartDate.RequiredErrorText)
            .Must(Common.BeOneDayInTheFuture)
            .WithMessage(VacancyViewModelMessages.PossibleStartDate.AfterTodayErrorText)
            .SetValidator(new DateViewModelClientValidator());
        }
        internal static void AddCommonRules(this AbstractValidator <ProviderViewModel> validator)
        {
            validator.RuleFor(m => m.Ukprn)
            .NotEmpty()
            .WithMessage(ProviderViewModelMessages.Ukprn.RequiredErrorText)
            .Length(8, 8)
            .WithMessage(ProviderViewModelMessages.Ukprn.RequiredLengthErrorText)
            .Matches(ProviderViewModelMessages.Ukprn.WhiteListRegularExpression)
            .WithMessage(ProviderViewModelMessages.Ukprn.WhiteListErrorText);

            validator.RuleFor(m => m.FullName)
            .NotEmpty()
            .WithMessage(ProviderViewModelMessages.FullName.RequiredErrorText)
            .Length(0, 255)
            .WithMessage(ProviderViewModelMessages.FullName.TooLongErrorText)
            .Matches(ProviderViewModelMessages.FullName.WhiteListRegularExpression)
            .WithMessage(ProviderViewModelMessages.FullName.WhiteListErrorText);

            validator.RuleFor(m => m.TradingName)
            .NotEmpty()
            .WithMessage(ProviderViewModelMessages.TradingName.RequiredErrorText)
            .Length(0, 255)
            .WithMessage(ProviderViewModelMessages.TradingName.TooLongErrorText)
            .Matches(ProviderViewModelMessages.TradingName.WhiteListRegularExpression)
            .WithMessage(ProviderViewModelMessages.TradingName.WhiteListErrorText);
        }
        internal static void AddCommonRules(this AbstractValidator <SettingsViewModel> validator)
        {
            validator.RuleFor(x => x.DateOfBirth).SetValidator(new DateOfBirthViewModelClientValidator());
            validator.RuleFor(x => x.Address).SetValidator(new AddressViewModelValidator());

            validator.RuleFor(x => x.Firstname)
            .Length(0, 35)
            .WithMessage(SettingsViewModelMessages.FirstnameMessages.TooLongErrorText)
            .NotEmpty()
            .WithMessage(SettingsViewModelMessages.FirstnameMessages.RequiredErrorText)
            .Matches(SettingsViewModelMessages.FirstnameMessages.WhiteListRegularExpression)
            .WithMessage(SettingsViewModelMessages.FirstnameMessages.WhiteListErrorText);

            validator.RuleFor(x => x.Lastname)
            .Length(0, 35)
            .WithMessage(SettingsViewModelMessages.LastnameMessages.TooLongErrorText)
            .NotEmpty()
            .WithMessage(SettingsViewModelMessages.LastnameMessages.RequiredErrorText)
            .Matches(SettingsViewModelMessages.LastnameMessages.WhiteListRegularExpression)
            .WithMessage(SettingsViewModelMessages.LastnameMessages.WhiteListErrorText);

            validator.RuleFor(x => x.PhoneNumber)
            .Length(8, 16)
            .WithMessage(SettingsViewModelMessages.PhoneNumberMessages.LengthErrorText)
            .NotEmpty()
            .WithMessage(SettingsViewModelMessages.PhoneNumberMessages.RequiredErrorText)
            .Matches(SettingsViewModelMessages.PhoneNumberMessages.WhiteListRegularExpression)
            .WithMessage(SettingsViewModelMessages.PhoneNumberMessages.WhiteListErrorText);
        }
        internal static void AddCommonRules(this AbstractValidator <ContactMessageViewModel> validator)
        {
            validator.RuleFor(x => x.Name)
            .Length(0, 71)
            .WithMessage(ContactMessageViewModelMessages.FullNameMessages.TooLongErrorText)
            .NotEmpty()
            .WithMessage(ContactMessageViewModelMessages.FullNameMessages.RequiredErrorText)
            .Matches(ContactMessageViewModelMessages.FullNameMessages.WhiteListRegularExpression)
            .WithMessage(ContactMessageViewModelMessages.FullNameMessages.WhiteListErrorText);


            validator.RuleFor(x => x.Email)
            .Length(0, 100)
            .WithMessage(ContactMessageViewModelMessages.EmailAddressMessages.TooLongErrorText)
            .NotEmpty()
            .WithMessage(ContactMessageViewModelMessages.EmailAddressMessages.RequiredErrorText)
            .Matches(ContactMessageViewModelMessages.EmailAddressMessages.WhiteListRegularExpression)
            .WithMessage(ContactMessageViewModelMessages.EmailAddressMessages.WhiteListErrorText);

            validator.RuleFor(x => x.Enquiry)
            .Length(0, 100)
            .WithMessage(ContactMessageViewModelMessages.EnquiryMessages.TooLongErrorText)
            .NotEmpty()
            .WithMessage(ContactMessageViewModelMessages.EnquiryMessages.RequiredErrorText)
            .Matches(ContactMessageViewModelMessages.EnquiryMessages.WhiteListRegularExpression)
            .WithMessage(ContactMessageViewModelMessages.EnquiryMessages.WhiteListErrorText);;

            validator.RuleFor(x => x.Details)
            .Length(0, 4000)
            .WithMessage(ContactMessageViewModelMessages.DetailsMessages.TooLongErrorText)
            .Matches(ContactMessageViewModelMessages.DetailsMessages.WhiteListRegularExpression)
            .WithMessage(ContactMessageViewModelMessages.DetailsMessages.WhiteListErrorText);
        }
Exemplo n.º 5
0
        internal static void AddCommonRules(this AbstractValidator <VacancyQuestionsViewModel> validator)
        {
            validator.RuleFor(x => x.FirstQuestion)
            .Length(0, 4000)
            .WithMessage(VacancyViewModelMessages.FirstQuestion.TooLongErrorText)
            .Matches(VacancyViewModelMessages.FirstQuestion.WhiteListTextRegularExpression)
            .WithMessage(VacancyViewModelMessages.FirstQuestion.WhiteListInvalidCharacterErrorText)
            .Must(Validators.Common.BeAValidFreeText)
            .WithMessage(VacancyViewModelMessages.FirstQuestion.WhiteListInvalidTagErrorText)
            .When(x => Common.IsNotEmpty(x.FirstQuestion));

            validator.RuleFor(x => x.SecondQuestion)
            .Length(0, 4000)
            .WithMessage(VacancyViewModelMessages.SecondQuestion.TooLongErrorText)
            .Matches(VacancyViewModelMessages.SecondQuestion.WhiteListTextRegularExpression)
            .WithMessage(VacancyViewModelMessages.SecondQuestion.WhiteListInvalidCharacterErrorText)
            .Must(Validators.Common.BeAValidFreeText)
            .WithMessage(VacancyViewModelMessages.SecondQuestion.WhiteListInvalidTagErrorText)
            .When(x => Common.IsNotEmpty(x.SecondQuestion));

            validator.RuleFor(x => x.FirstQuestionComment)
            .Matches(VacancyViewModelMessages.FirstQuestion.WhiteListTextRegularExpression)
            .WithMessage(VacancyViewModelMessages.FirstQuestion.WhiteListInvalidCharacterErrorText);

            validator.RuleFor(x => x.SecondQuestionComment)
            .Matches(VacancyViewModelMessages.SecondQuestion.WhiteListTextRegularExpression)
            .WithMessage(VacancyViewModelMessages.SecondQuestion.WhiteListInvalidCharacterErrorText);
        }
Exemplo n.º 6
0
        internal static void AddCommonRules(this AbstractValidator <ApprenticeshipApplicationViewModel> validator)
        {
            validator.RuleFor(x => x.Notes)
            .Matches(ApplicationViewModelMessages.Notes.WhiteListRegularExpression)
            .WithMessage(ApplicationViewModelMessages.Notes.WhiteListErrorText);

            validator.RuleFor(x => x.UnSuccessfulReason)
            .Matches(ApplicationViewModelMessages.UnSuccessfulReason.WhiteListRegularExpression)
            .WithMessage(ApplicationViewModelMessages.UnSuccessfulReason.WhiteListErrorText);
        }
Exemplo n.º 7
0
        public static void RuleForNameLength <T>(this AbstractValidator <T> validator,
                                                 Expression <Func <T, string> > property, int minLength, int maxLength)
        {
            Argument.NotNull(validator);

            validator.RuleFor(property).Must(x => x.Length >= minLength)
            .WithLocalizedMessage(() => ValidationMessages.NameTooShortMsg);
            validator.RuleFor(property).Must(x => x.Length < maxLength)
            .WithLocalizedMessage(() => ValidationMessages.NameTooLongMsg);
        }
Exemplo n.º 8
0
        internal static void AddCommonRules(this AbstractValidator <LoginViewModel> validator)
        {
            validator.RuleFor(model => model.EmailAddress)
            .NotEmpty()
            .WithMessage(LoginViewModelMessages.EmailAddressMessages.RequiredErrorText);

            validator.RuleFor(model => model.Password)
            .NotEmpty()
            .WithMessage(LoginViewModelMessages.PasswordMessages.RequiredErrorText);
        }
        internal static void AddClientRules(this AbstractValidator <EmployerQuestionAnswersViewModel> validator)
        {
            validator.RuleFor(x => x.CandidateAnswer1)
            .NotEmpty()
            .WithMessage(EmployerQuestionAnswersViewModelMessages.CandidateAnswer1Messages.RequiredErrorText);

            validator.RuleFor(x => x.CandidateAnswer2)
            .NotEmpty()
            .WithMessage(EmployerQuestionAnswersViewModelMessages.CandidateAnswer2Messages.RequiredErrorText);
        }
        internal static void AddServerRules(this AbstractValidator <EmployerQuestionAnswersViewModel> validator)
        {
            validator.RuleFor(x => x.CandidateAnswer1)
            .NotEmpty().When(x => !string.IsNullOrWhiteSpace(x.SupplementaryQuestion1))
            .WithMessage(EmployerQuestionAnswersViewModelMessages.CandidateAnswer1Messages.RequiredErrorText);

            validator.RuleFor(x => x.CandidateAnswer2)
            .NotEmpty().When(x => !string.IsNullOrWhiteSpace(x.SupplementaryQuestion2))
            .WithMessage(EmployerQuestionAnswersViewModelMessages.CandidateAnswer2Messages.RequiredErrorText);
        }
        public static void AddServerRules(this AbstractValidator <PasswordResetViewModel> validator)
        {
            validator.RuleFor(x => x.PasswordResetCode)
            .Must(IsPasswordResetCodeValid)
            .WithMessage(PasswordResetPageMessages.InvalidCode);

            validator.RuleFor(x => x.Password)
            .Equal(x => x.ConfirmPassword)
            .WithMessage(PasswordResetViewModelMessages.PasswordMessages.PasswordsDoNotMatchErrorText);
        }
Exemplo n.º 12
0
        internal static void AddCommonRules(this AbstractValidator <VacancyDatesViewModel> validator)
        {
            validator.RuleFor(viewModel => viewModel.ClosingDateComment)
            .Matches(VacancyViewModelMessages.Comment.WhiteListRegularExpression)
            .WithMessage(VacancyViewModelMessages.Comment.WhiteListErrorText);

            validator.RuleFor(viewModel => viewModel.PossibleStartDateComment)
            .Matches(VacancyViewModelMessages.Comment.WhiteListRegularExpression)
            .WithMessage(VacancyViewModelMessages.Comment.WhiteListErrorText);
        }
Exemplo n.º 13
0
        internal static void AddCommonRules(this AbstractValidator <LocationSearchViewModel> validator)
        {
            validator.RuleFor(viewModel => viewModel.AdditionalLocationInformation)
            .Matches(LocationSearchViewModelMessages.AdditionalLocationInformation.WhiteListRegularExpression)
            .WithMessage(LocationSearchViewModelMessages.AdditionalLocationInformation.WhiteListErrorText);

            validator.RuleFor(viewModel => viewModel.AdditionalLocationInformationComment)
            .Matches(LocationSearchViewModelMessages.AdditionalLocationInformationComment.WhiteListRegularExpression)
            .WithMessage(LocationSearchViewModelMessages.AdditionalLocationInformationComment.WhiteListErrorText);
        }
        internal static void AddCommonRules(this AbstractValidator <DeleteAccountSettingsViewModel> validator)
        {
            validator.RuleFor(x => x.EmailAddress)
            .NotEmpty()
            .WithMessage(SettingsViewModelMessages.EmailAddressMessages.RequiredErrorText);

            validator.RuleFor(x => x.Password)
            .NotEmpty()
            .WithMessage(SettingsViewModelMessages.PasswordMessages.RequiredErrorText);
        }
Exemplo n.º 15
0
        public static void RegisterRules <T>(this AbstractValidator <T> validator) where T : CreateProductCommand
        {
            validator.RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("O campo Nome está vazio ")
            .When(x => !x.Name.IsNull());

            validator.RuleFor(x => x.Description)
            .NotEmpty()
            .WithMessage("O campo Descrição está vazio")
            .When(x => !x.Description.IsNull());
        }
Exemplo n.º 16
0
        protected override void ValidateSubject(AbstractValidator <EditMessageTemplate> validator)
        {
            validator.When(x => _messageTemplate.MessageDeliveryMethod == MessageDeliveryMethod.Email,
                           () => validator.RuleFor(x => x.Subject)
                           .NotEmpty()
                           .WithMessage(MessagingValidationError.Required));

            validator.When(x => _messageTemplate.MessageDeliveryMethod == MessageDeliveryMethod.Sms,
                           () => validator.RuleFor(x => x.Subject)
                           .Must(string.IsNullOrWhiteSpace)
                           .WithMessage(MessagingValidationError.SubjectNotApplicable));
        }
Exemplo n.º 17
0
        public static void AddServerRules(this AbstractValidator <ApprenticeshipSearchViewModel> validator)
        {
            validator.RuleFor(x => x.Location)
            .Length(3, 99)
            .When(IsKeywordOrCategorySearch)
            .When(x => x.Location != null && !x.Location.Any(Char.IsDigit) && !VacancyHelper.IsVacancyReference(x.Keywords))
            .WithMessage(ApprenticeshipSearchViewModelMessages.LocationMessages.LengthErrorText);

            validator.RuleFor(x => x.SavedSearchId)
            .NotEmpty()
            .When(x => x.SearchMode == ApprenticeshipSearchMode.SavedSearches)
            .WithMessage(ApprenticeshipSearchViewModelMessages.SavedSearchMessages.RequiredErrorText);
        }
Exemplo n.º 18
0
        internal static void AddServerRules(this AbstractValidator <RegisterViewModel> validator)
        {
            validator.RuleFor(x => x.DateOfBirth).SetValidator(new DateOfBirthViewModelServerValidator());

            validator.RuleFor(x => x.EmailAddress)
            .Must((model, emailAddress) => model.IsUsernameAvailable)
            .When(x => !string.IsNullOrWhiteSpace(x.EmailAddress))
            .WithMessage(RegisterViewModelMessages.EmailAddressMessages.UsernameNotAvailableErrorText);

            validator.RuleFor(x => x.Password)
            .Equal(x => x.ConfirmPassword)
            .WithMessage(RegisterViewModelMessages.PasswordMessages.PasswordsDoNotMatchErrorText);
        }
        internal static void AddMandatoryRules(this AbstractValidator <AboutYouViewModel> validator)
        {
            validator.RuleFor(x => x.WhatAreYourStrengths)
            .NotEmpty()
            .WithMessage(AboutYouViewModelMessages.WhatAreYourStrengthsMessages.RequiredErrorText);

            validator.RuleFor(x => x.WhatDoYouFeelYouCouldImprove)
            .NotEmpty()
            .WithMessage(AboutYouViewModelMessages.WhatDoYouFeelYouCouldImproveMessages.RequiredErrorText);

            validator.RuleFor(x => x.WhatAreYourHobbiesInterests)
            .NotEmpty()
            .WithMessage(AboutYouViewModelMessages.WhatAreYourHobbiesInterestsMessages.RequiredErrorText);
        }
        internal static void AddCommonRules(this AbstractValidator <EmployerQuestionAnswersViewModel> validator)
        {
            validator.RuleFor(x => x.CandidateAnswer1)
            .Length(0, 4000)
            .WithMessage(EmployerQuestionAnswersViewModelMessages.CandidateAnswer1Messages.TooLongErrorText)
            .Matches(EmployerQuestionAnswersViewModelMessages.CandidateAnswer1Messages.WhitelistRegularExpression)
            .WithMessage(EmployerQuestionAnswersViewModelMessages.CandidateAnswer1Messages.WhitelistErrorText);

            validator.RuleFor(x => x.CandidateAnswer2)
            .Length(0, 4000)
            .WithMessage(EmployerQuestionAnswersViewModelMessages.CandidateAnswer2Messages.TooLongErrorText)
            .Matches(EmployerQuestionAnswersViewModelMessages.CandidateAnswer2Messages.WhitelistRegularExpression)
            .WithMessage(EmployerQuestionAnswersViewModelMessages.CandidateAnswer2Messages.WhitelistErrorText);
        }
Exemplo n.º 21
0
        internal static void AddMandatoryRules(this AbstractValidator <EducationViewModel> validator)
        {
            validator.RuleFor(x => x.NameOfMostRecentSchoolCollege)
            .NotEmpty()
            .WithMessage(EducationViewModelMessages.NameOfMostRecentSchoolCollegeMessages.RequiredErrorText);

            validator.RuleFor(x => x.FromYear)
            .NotEmpty()
            .WithMessage(EducationViewModelMessages.FromYearMessages.RequiredErrorText);

            validator.RuleFor(x => x.ToYear)
            .NotEmpty()
            .WithMessage(EducationViewModelMessages.ToYearMessages.RequiredErrorText);
        }
Exemplo n.º 22
0
            public static void AddValidation(AbstractValidator <Command> v)
            {
                v.RuleFor(x => x.Name)
                .NotEmpty().WithMessage("Please enter name.");

                v.RuleFor(x => x.Gender)
                .Equal(0).WithMessage("Invalid gender.");

                v.RuleForEach(x => x.Locales).ChildRules(locales =>
                {
                    locales.RuleFor(x => x.Name)
                    .NotEmpty().WithMessage("Please enter name.");
                });
            }
Exemplo n.º 23
0
        internal static void AddCommonRules(this AbstractValidator <RegisterViewModel> validator)
        {
            validator.RuleFor(x => x.DateOfBirth).SetValidator(new DateOfBirthViewModelClientValidator());
            validator.RuleFor(x => x.Address).SetValidator(new AddressViewModelValidator());

            validator.RuleFor(x => x.Firstname)
            .Length(0, 35)
            .WithMessage(RegisterViewModelMessages.FirstnameMessages.TooLongErrorText)
            .NotEmpty()
            .WithMessage(RegisterViewModelMessages.FirstnameMessages.RequiredErrorText)
            .Matches(RegisterViewModelMessages.FirstnameMessages.WhiteListRegularExpression)
            .WithMessage(RegisterViewModelMessages.FirstnameMessages.WhiteListErrorText);

            validator.RuleFor(x => x.Lastname)
            .Length(0, 35)
            .WithMessage(RegisterViewModelMessages.LastnameMessages.TooLongErrorText)
            .NotEmpty()
            .WithMessage(RegisterViewModelMessages.LastnameMessages.RequiredErrorText)
            .Matches(RegisterViewModelMessages.LastnameMessages.WhiteListRegularExpression)
            .WithMessage(RegisterViewModelMessages.LastnameMessages.WhiteListErrorText);

            validator.RuleFor(x => x.EmailAddress)
            .Length(0, 100)
            .WithMessage(RegisterViewModelMessages.EmailAddressMessages.TooLongErrorText)
            .NotEmpty()
            .WithMessage(RegisterViewModelMessages.EmailAddressMessages.RequiredErrorText)
            .Matches(RegisterViewModelMessages.EmailAddressMessages.WhiteListRegularExpression)
            .WithMessage(RegisterViewModelMessages.EmailAddressMessages.WhiteListErrorText);

            validator.RuleFor(x => x.PhoneNumber)
            .Length(8, 16)
            .WithMessage(RegisterViewModelMessages.PhoneNumberMessages.LengthErrorText)
            .NotEmpty()
            .WithMessage(RegisterViewModelMessages.PhoneNumberMessages.RequiredErrorText)
            .Matches(RegisterViewModelMessages.PhoneNumberMessages.WhiteListRegularExpression)
            .WithMessage(RegisterViewModelMessages.PhoneNumberMessages.WhiteListErrorText);

            validator.RuleFor(x => x.Password)
            .Length(8, 127)
            .WithMessage(RegisterViewModelMessages.PasswordMessages.LengthErrorText)
            .NotEmpty()
            .WithMessage(RegisterViewModelMessages.PasswordMessages.RequiredErrorText)
            .Matches(RegisterViewModelMessages.PasswordMessages.WhiteListRegularExpression)
            .WithMessage(RegisterViewModelMessages.PasswordMessages.WhiteListErrorText);

            validator.RuleFor(x => x.ConfirmPassword)
            .NotEmpty()
            .WithMessage(RegisterViewModelMessages.ConfirmPasswordMessages.RequiredErrorText);

            validator.RuleFor(x => x.HasAcceptedTermsAndConditions)
            .Equal(true)
            .WithMessage(RegisterViewModelMessages.TermsAndConditions.MustAcceptTermsAndConditions);
        }
        internal static void AddCommonRules(this AbstractValidator <ApiUserViewModel> validator)
        {
            validator.RuleFor(m => m.Password)
            .Length(16)
            .WithMessage(ApiUserViewModelMessages.Password.RequiredLengthErrorText)
            .Matches(ApiUserViewModelMessages.Password.WhiteListRegularExpression)
            .WithMessage(ApiUserViewModelMessages.Password.WhiteListErrorText);

            validator.RuleFor(m => m.CompanyId)
            .NotEmpty()
            .WithMessage(ApiUserViewModelMessages.CompanyId.RequiredErrorText)
            .Length(8, 9)
            .WithMessage(ApiUserViewModelMessages.CompanyId.RequiredLengthErrorText)
            .Matches(ApiUserViewModelMessages.CompanyId.WhiteListRegularExpression)
            .WithMessage(ApiUserViewModelMessages.CompanyId.WhiteListErrorText);
        }
 public static void AddLocationRules(this AbstractValidator <TraineeshipSearchViewModel> validator)
 {
     // NOTE: no message here, 'no results' help text provides suggestions to user.
     validator.RuleFor(x => x.Location)
     .Must(HaveLatAndLongPopulated)
     .When(x => !VacancyHelper.IsVacancyReference(x.ReferenceNumber));
 }
 public static void AddServerRules(this AbstractValidator <TraineeshipSearchViewModel> validator)
 {
     validator.RuleFor(x => x.Location)
     .Length(3, 99)
     .When(x => x.Location != null && !x.Location.Any(Char.IsDigit))
     .WithMessage(TraineeshipSearchViewModelMessages.LocationMessages.LengthErrorText);
 }
Exemplo n.º 27
0
 public static void UserIdValidator <T>(this AbstractValidator <T> validator, IUnitOfWork unitOfWork) where T : IUserId
 {
     validator.RuleFor(c => c.UserId)
     .NotEmpty()
     .MustAsync((userId, _) => unitOfWork.UserRepository.Exist(userId))
     .WithMessage(command => "{PropertyName} does not exist");
 }
Exemplo n.º 28
0
        /// <summary>
        /// Adds the base filter validations.
        /// </summary>
        /// <typeparam name="T">a Base filter model</typeparam>
        /// <param name="baseFilter">The base filter.</param>
        public static void AddBaseFilterValidations <T>(this AbstractValidator <T> baseFilter) where T : BaseFilterModel
        {
            baseFilter.RuleFor(c => c.PageSize)
            .GreaterThan(0)
            .LessThanOrEqualTo(c => c.MaxPageSize)
            .WithMessage(c => $"Tamaño máximo de paginación excedido. El máximo es {c.MaxPageSize}");

            baseFilter.RuleFor(c => c.Page)
            .GreaterThanOrEqualTo(0)
            .WithMessage("La pagina debe ser mayor a 0");

            baseFilter.RuleFor(c => c)
            .Must(c => string.IsNullOrEmpty(c.OrderBy) || (!string.IsNullOrEmpty(c.OrderBy) && c.ValidOrdersBy.Contains(c.OrderBy)))
            .WithMessage(c => $"El parametro orderBy no es valido. Las opciones son: {string.Join(",", c.ValidOrdersBy)}")
            .OverridePropertyName("OrderBy");
        }
Exemplo n.º 29
0
        internal static void AddCommonRules(this AbstractValidator <VacancyLocationAddressViewModel> validator)
        {
            validator.RuleFor(x => x.NumberOfPositions)
            .NotEmpty()
            .WithMessage(VacancyLocationAddressViewModelMessages.NumberOfPositions.RequiredErrorText)
            .GreaterThanOrEqualTo(1)
            .WithMessage(VacancyLocationAddressViewModelMessages.NumberOfPositions.AtLeastOnePositionErrorText);

            validator.RuleFor(viewModel => viewModel.OfflineApplicationUrl)
            .Length(0, 256)
            .WithMessage(VacancyViewModelMessages.OfflineApplicationUrl.TooLongErrorText);

            validator.RuleFor(viewModel => viewModel.OfflineApplicationUrl)
            .Matches(VacancyViewModelMessages.OfflineApplicationUrl.WhiteListRegularExpression)
            .WithMessage(VacancyViewModelMessages.OfflineApplicationUrl.WhiteListErrorText);
        }
Exemplo n.º 30
0
 public static void AddServerRules(this AbstractValidator <ApprenticeshipSearchViewModel> validator)
 {
     validator.RuleFor(x => x.Location)
     .Length(3, 99)
     .When(x => x.Location != null && !x.Location.Any(Char.IsDigit) && !VacancyHelper.IsVacancyReference(x.Keywords))
     .WithMessage(ApprenticeshipSearchViewModelMessages.LocationMessages.LengthErrorText);
 }