Esempio n. 1
0
        public UpdateMyAffiliationValidator(IQueryEntities entities)
        {
            CascadeMode = CascadeMode.StopOnFirstFailure;

            var eagerLoad = new Expression <Func <Establishment, object> >[]
            {
                e => e.Type.Category,
            };

            RuleFor(p => p.Principal)
            // principal cannot be null
            .NotEmpty()
            .WithMessage(ValidatePrincipal.FailedBecausePrincipalWasNull)
            // principal.identity.name cannot be null, empty, or whitespace
            .Must(ValidatePrincipal.IdentityNameIsNotEmpty)
            .WithMessage(ValidatePrincipal.FailedBecauseIdentityNameWasEmpty)
            // principal.identity.name must match User.Name entity property
            .Must(p => ValidatePrincipal.IdentityNameMatchesUser(p, entities))
            .WithMessage(ValidatePrincipal.FailedBecauseIdentityNameMatchedNoUser,
                         p => p.Principal.Identity.Name)
            ;

            RuleFor(p => p.EstablishmentId)
            // establishment id must exist in database
            .Must(p => ValidateEstablishment.IdMatchesEntity(p, entities, eagerLoad))
            .WithMessage(ValidateEstablishment.FailedBecauseIdMatchedNoEntity,
                         p => p.EstablishmentId)
            ;
        }
Esempio n. 2
0
        public UpdateMyEmailValueValidator(IQueryEntities entities)
        {
            CascadeMode = CascadeMode.StopOnFirstFailure;

            EmailAddress email = null;

            RuleFor(p => p.Principal)
            // principal cannot be null
            .NotEmpty()
            .WithMessage(ValidatePrincipal.FailedBecausePrincipalWasNull)
            // principal identity name cannot be null or whitespace
            .Must(ValidatePrincipal.IdentityNameIsNotEmpty)
            .WithMessage(ValidatePrincipal.FailedBecauseIdentityNameWasEmpty)
            // principal identity name must match User.Name entity property
            .Must(p => ValidatePrincipal.IdentityNameMatchesUser(p, entities))
            .WithMessage(ValidatePrincipal.FailedBecauseIdentityNameMatchedNoUser,
                         p => p.Principal.Identity.Name)
            ;

            RuleFor(p => p.Number)
            // number must match email for user
            .Must((o, p) => ValidateEmailAddress.NumberAndPrincipalMatchesEntity(p, o.Principal, entities, out email))
            .When(p => p.Principal != null && p.Principal.Identity.Name != null)
            .WithMessage(ValidateEmailAddress.FailedBecauseNumberAndPrincipalMatchedNoEntity,
                         p => p.Number, p => p.Principal.Identity.Name)
            ;

            RuleFor(p => p.NewValue)
            // new email address cannot be empty
            .NotEmpty()
            .WithMessage(ValidateEmailAddress.FailedBecauseValueWasEmpty)
            // must be valid against email address regular expression
            .EmailAddress()
            .WithMessage(ValidateEmailAddress.FailedBecauseValueWasNotValidEmailAddress,
                         p => p.NewValue)
            ;

            RuleFor(p => p.NewValue)
            // must match previous spelling case insensitively
            .Must(p => ValidateEmailAddress.NewValueMatchesCurrentValueCaseInsensitively(p, email))
            .When(p => email != null)
            .WithMessage(ValidateEmailAddress.FailedBecauseNewValueDidNotMatchCurrentValueCaseInvsensitively,
                         p => p.NewValue)
            ;
        }
Esempio n. 3
0
        public UpdateMyNameValidator(IQueryEntities entities)
        {
            CascadeMode = CascadeMode.StopOnFirstFailure;

            RuleFor(p => p.DisplayName)
            // display name cannot be empty
            .NotEmpty()
            .WithMessage(ValidatePerson.FailedBecauseDisplayNameWasEmpty)
            ;

            RuleFor(p => p.Principal)
            // principal cannot be null
            .NotEmpty()
            .WithMessage(ValidatePrincipal.FailedBecausePrincipalWasNull)
            // principal identity name cannot be null or whitespace
            .Must(ValidatePrincipal.IdentityNameIsNotEmpty)
            .WithMessage(ValidatePrincipal.FailedBecauseIdentityNameWasEmpty)
            // principal identity name must match User.Name entity property
            .Must(p => ValidatePrincipal.IdentityNameMatchesUser(p, entities))
            .WithMessage(ValidatePrincipal.FailedBecauseIdentityNameMatchedNoUser,
                         p => p.Principal.Identity.Name)
            ;
        }