public ChangePasswordViewModel ChangePassword(int userId, ChangePasswordViewModel model) { exceptionService.Execute((m) => { if (model.NewPassword != model.ConfirmPassword) { model.AddModelError(x => x.NewPassword, "New password and confirm new password not matched.", "New password and confirm new password not matched."); return; } var oldUser = userRepository.GetById(userId); var encSvc = new EncryptionService(); string pass = encSvc.CreatePasswordHash(model.OldPassword, oldUser.Salt); if (oldUser.Password != pass) { model.AddModelError(x => x.OldPassword, "Message.OldPasswordNotMatched", string.Format("{0} not matched.", model.GetDisplayName(x => x.OldPassword))); return; } oldUser.Password = encSvc.CreatePasswordHash(model.ConfirmPassword, oldUser.Salt); userRepository.Update(oldUser); model.Message = localizationService.GetLocalizedText("Message.RecordUpdatedSuccessfully", IMSAppConfig.Instance.CurrentLanguage, "Record update succeeded."); }, model); return(model); }