public string ChangePassword(ChangePaswordModel model) { var user = _unitOfWork.Users.Single(s => s.LoginId == model.LoginId); if (user != null) { int dealerId = user.EmployeeId ?? 0; var userOtp = _unitOfWork.UserOtp.Single(s => s.UserId == user.UserId && s.Password == model.Token && s.IsUsedToken == false); if (userOtp != null) { if (userOtp.ValidToDate >= DateTime.Now) { var hashPass = EncryptDecryptHelper.Encrypt(model.NewPassword); var objUser = _unitOfWork.Users.GetById(userOtp.UserId); objUser.Password = hashPass; objUser.LastUpdateDate = DateTime.Now; objUser.FailedLoginNo = 0; objUser.IsExpired = false; objUser.LastLoginDate = DateTime.Now; objUser.IsFirstLoginEnable = false; _unitOfWork.Users.Update(objUser); userOtp.IsUsedToken = true; _unitOfWork.UserOtp.Update(userOtp); _unitOfWork.Commit(); _userNotificationService.SendPasswordChangedAcknowledge(user); return("Success"); } else { throw new Exception("Token has been expired"); } } else { throw new Exception("Token has been expired"); } } else { throw new Exception("Token already used"); } return(null); }