public PasswordValidator(string password, string confirmPassword) { StringArgumentValidator.IsNullOrEmpty(password, nameof(password)); StringArgumentValidator.IsNullOrEmpty(confirmPassword, nameof(confirmPassword)); Password = password; ConfirmPassword = confirmPassword; }
public IEnumerable <UserIncludeValuesDto> GetUsersByName(string name) { StringArgumentValidator.IsNullOrEmpty(name, nameof(name)); return(GetUsersWithIncludes().Where(user => user.FullName.ToLower().Contains(name.ToLower())) .Select(prop => _mapper.Map <UserIncludeValuesDto>(prop)) .AsEnumerable()); }
public StringValidator(string text, int minLength, int maxLength, string exceptionMessage) { StringArgumentValidator.IsNullOrEmpty(text, nameof(text)); StringArgumentValidator.IsNullOrEmpty(exceptionMessage, nameof(exceptionMessage)); Text = text; MaxLength = maxLength; MinLength = minLength; ExceptionMessage = exceptionMessage; }
public UserIncludeValuesDto GetUserByEmail(string email) { StringArgumentValidator.IsNullOrEmpty(email, nameof(email)); var userWithSpecifiedEmail = GetUsersWithIncludes().FirstOrDefault(user => user.Email.ToLower().Equals(email.ToLower())); if (userWithSpecifiedEmail == null) { throw new ObjectNotFoundException(ExceptionStrings.UserNotFoundException, email); } return(_mapper.Map <UserIncludeValuesDto>(userWithSpecifiedEmail)); }
public UserIncludeValuesDto GetUserByPhoneNumber(string phoneNumber) { StringArgumentValidator.IsNullOrEmpty(phoneNumber, nameof(phoneNumber)); var userWithSpecifiedPhoneNumber = GetUsersWithIncludes().FirstOrDefault(user => user.PhoneNumber.Equals(phoneNumber)); if (userWithSpecifiedPhoneNumber == null) { throw new ObjectNotFoundException(ExceptionStrings.UserNotFoundException, phoneNumber); } return(_mapper.Map <UserIncludeValuesDto>(userWithSpecifiedPhoneNumber)); }
public async Task DeleteUser(string id) { StringArgumentValidator.IsNullOrEmpty(id, nameof(id)); var admin = await _userManager.FindByIdAsync(id); if (admin == null) { throw new ObjectNotFoundException(ExceptionStrings.UserNotFoundException, id); } var deleteAdminResult = await _userManager.DeleteAsync(admin); if (!deleteAdminResult.Succeeded) { throw new ObjectDeleteException(ExceptionStrings.UserDeleteException, id); } }
public async Task <IEnumerable <UserIncludeValuesDto> > GetUsersInRole(string role) { StringArgumentValidator.IsNullOrEmpty(role, nameof(role)); var formatedRole = role.ToLowerCaseWithFirstLetterInUpper(); if (!Roles.RoleStrings.Contains(formatedRole)) { throw new RoleException(ExceptionStrings.RoleNotFoundException, formatedRole); } var usersInRole = await _userManager.GetUsersInRoleAsync(formatedRole); var users = GetUsersWithIncludes().AsEnumerable() .Where(user => usersInRole.Contains(user)) .Select(prop => _mapper.Map <UserIncludeValuesDto>(prop)); return(users); }
public EmailValidator(string email) { StringArgumentValidator.IsNullOrEmpty(email, nameof(email)); Email = email; }
public PhoneNumberValidator(string phoneNumber) { StringArgumentValidator.IsNullOrEmpty(phoneNumber, nameof(phoneNumber)); PhoneNumber = phoneNumber; }
public void Add_WhenValidatorExist_ShouldThrowException() { var v = new StringArgumentValidator(); this.validators.Add(v); }