Пример #1
0
 public void UpdatePassword(int id, string oldPassword, string newPassword)
 {
     using (var unitOfWork = new UnitOfWork())
     {
         var userRepository = unitOfWork.GetRepository <User>();
         var user           = userRepository.Find(id);
         if (user == null)
         {
             throw new NotFoundException("User not in database");
         }
         if (user.Password == oldPassword)
         {
             user.Password = newPassword;
             userRepository.Update(user);
             unitOfWork.Save();
         }
         else
         {
             throw new InvalidModelException("Parola veche introdusa este incorecta.");
         }
         PasswordValidator passwordValidator = new PasswordValidator();
         var checkResult = passwordValidator.Check(newPassword);
         if (checkResult.Count != 0)
         {
             throw new InvalidModelException(String.Join("\n", checkResult.ToArray()));
         }
     }
 }