private async Task ValidateEmailAsync(string email, List <ErrorDetails> errors) { if (errors is null) { throw new ArgumentNullException(nameof(errors)); } if (string.IsNullOrWhiteSpace(email)) { errors.Add(ApplicationUserErrors.EmailRequired()); return; } if (email.Length > MaximumEmailLength) { errors.Add(ApplicationUserErrors.EmailTooLong()); } else if (!_emailAddressAttribute.IsValid(email)) { errors.Add(ApplicationUserErrors.EmailInvalidFormat()); } else { var user = await _usersRepository.GetByEmailAsync(email); if (user is object && string.Equals(user.Email, email, StringComparison.OrdinalIgnoreCase)) { errors.Add(ApplicationUserErrors.EmailAlreadyExists()); } } }
private static void ValidatePhoneNumber(string phoneNumber, List <ErrorDetails> errors) { if (errors is null) { throw new ArgumentNullException(nameof(errors)); } if (string.IsNullOrWhiteSpace(phoneNumber)) { errors.Add(ApplicationUserErrors.PhoneNumberRequired()); return; } if (phoneNumber.Length > MaximumPhoneNumberLength) { errors.Add(ApplicationUserErrors.PhoneNumberTooLong()); } }
private static void ValidateLastName(string lastName, List <ErrorDetails> errors) { if (errors is null) { throw new ArgumentNullException(nameof(errors)); } if (string.IsNullOrWhiteSpace(lastName)) { errors.Add(ApplicationUserErrors.LastNameRequired()); return; } if (lastName.Length > MaximumLastNameLength) { errors.Add(ApplicationUserErrors.LastNameTooLong()); } }