private string FormatEmailForSearch(SearchUserSummariesQuery query) { const string PLACEHOLDER_DOMAIN = "@example.com"; var email = query.Email; var isPartialEmail = !email.Contains("@"); if (isPartialEmail) { // we can only assume it's the local part of the email email = query.Email + PLACEHOLDER_DOMAIN; } var uniqueEmail = _userDataFormatter.UniquifyEmail(query.UserAreaCode, email); if (uniqueEmail == null) { // if it could not be parsed, just stick with the original uniqueEmail = query.Email; } else if (isPartialEmail) { uniqueEmail = email.Replace(PLACEHOLDER_DOMAIN, string.Empty); } return(uniqueEmail); }
public async Task <bool> ExecuteAsync(IsUserEmailAddressUniqueQuery query, IExecutionContext executionContext) { var uniqueEmailAddress = _userDataFormatter.UniquifyEmail(query.UserAreaCode, query.Email); if (string.IsNullOrWhiteSpace(uniqueEmailAddress)) { return(true); } var exists = await _dbContext .Users .AsNoTracking() .FilterNotDeleted() .FilterByUserArea(query.UserAreaCode) .Where(u => u.UserId != query.UserId && u.UniqueEmail == uniqueEmailAddress) .AnyAsync(); return(!exists); }