Пример #1
0
        public PasswordValidator(string password, string confirmPassword)
        {
            StringArgumentValidator.IsNullOrEmpty(password, nameof(password));
            StringArgumentValidator.IsNullOrEmpty(confirmPassword, nameof(confirmPassword));

            Password        = password;
            ConfirmPassword = confirmPassword;
        }
Пример #2
0
        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());
        }
Пример #3
0
 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;
 }
Пример #4
0
        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));
        }
Пример #5
0
        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));
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        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);
        }
Пример #8
0
        public EmailValidator(string email)
        {
            StringArgumentValidator.IsNullOrEmpty(email, nameof(email));

            Email = email;
        }
Пример #9
0
        public PhoneNumberValidator(string phoneNumber)
        {
            StringArgumentValidator.IsNullOrEmpty(phoneNumber, nameof(phoneNumber));

            PhoneNumber = phoneNumber;
        }
        public void Add_WhenValidatorExist_ShouldThrowException()
        {
            var v = new StringArgumentValidator();

            this.validators.Add(v);
        }