/// <summary>
        /// Validates a user email address, throwing a <see cref="ValidationErrorException"/>
        /// if any errors are found. By default the validator checks that the format contains only
        /// the characters permitted by the <see cref="EmailAddressOptions"/> configuration settings,
        /// as well as checking for uniquness.
        /// </summary>
        public static async Task ValidateAsync(this IEmailAddressValidator emailAddressValidator, IEmailAddressValidationContext context)
        {
            var result = await emailAddressValidator.GetErrorsAsync(context);

            if (result.Any())
            {
                throw new ValidationErrorException(result.First());
            }
        }
예제 #2
0
        public async Task <ValidationQueryResult> ExecuteAsync(ValidateUserEmailAddressQuery query, IExecutionContext executionContext)
        {
            var userArea         = _userAreaDefinitionRepository.GetRequiredByCode(query.UserAreaCode);
            var formattingResult = _userDataFormatter.FormatEmailAddress(userArea, query.Email);

            var context = new EmailAddressValidationContext()
            {
                Email            = formattingResult,
                ExecutionContext = executionContext,
                PropertyName     = nameof(query.Email),
                UserAreaCode     = userArea.UserAreaCode,
                UserId           = query.UserId
            };

            var errors = await _emailAddressValidator.GetErrorsAsync(context);

            var result = new ValidationQueryResult(errors.FirstOrDefault());

            return(result);
        }