Esempio n. 1
0
 public IActionResult Update([FromBody] UserCommandViewModel user)
 {
     try
     {
         _userService.Update(user);
         return(StatusCode(200));
     }
     catch (ArgumentException)
     {
         return(StatusCode(400));
     }
     catch (InexistentResourceException)
     {
         return(StatusCode(401));
     }
     catch (Exception)
     {
         return(StatusCode(500));
     }
 }
Esempio n. 2
0
        public void Update(UserCommandViewModel updatedUser)
        {
            if (updatedUser.FirstName.Equals("") || updatedUser.LastName.Equals("") || updatedUser.Email.Equals("") ||
                updatedUser.OldPassword.Equals("") || updatedUser.NewPassword.Equals("") || updatedUser.RepeatPassword.Equals(""))
            {
                throw new ArgumentException("Empty field");
            }
            if (!updatedUser.NewPassword.Equals(updatedUser.RepeatPassword))
            {
                throw new ArgumentException("New password is not the same as Repeat Password");
            }
            var actualUser = _userRepository.GetUser(updatedUser.Id, PasswordEncoder.EncodePasswordMd5(updatedUser.OldPassword));

            if (actualUser == null)
            {
                throw new InexistentResourceException("Invalid combination of id and password");
            }
            actualUser.FirstName = updatedUser.FirstName;
            actualUser.LastName  = updatedUser.LastName;
            actualUser.Email     = updatedUser.Email;
            actualUser.Password  = PasswordEncoder.EncodePasswordMd5(updatedUser.NewPassword);
            _userRepository.Update(actualUser);
        }