/// <summary> /// Validates that the email is not already registered with another user. /// </summary> protected virtual async Task <ValidationError> ValidateUniqueAsync(IEmailAddressValidationContext context) { var userArea = _userAreaDefinitionRepository.GetRequiredByCode(context.UserAreaCode); var options = _userAreaDefinitionRepository.GetOptionsByCode(context.UserAreaCode).EmailAddress; if (!options.RequireUnique && !userArea.UseEmailAsUsername) { return(null); } var query = new IsUserEmailAddressUniqueQuery() { Email = context.Email.UniqueEmailAddress, UserAreaCode = context.UserAreaCode }; if (context.UserId.HasValue) { query.UserId = context.UserId.Value; } var isUnique = await _domainRepository .WithContext(context.ExecutionContext) .ExecuteQueryAsync(query); if (isUnique) { return(null); } return(UserValidationErrors .EmailAddress .NotUnique .Create(context.PropertyName)); }
public IDomainRepositoryQueryContext <bool> IsEmailAddressUnique(IsUserEmailAddressUniqueQuery query) { return(DomainRepositoryQueryContextFactory.Create(query, ExtendableContentRepository)); }