public bool ChangeOldPassword(ChangePasswordModel model) { if (string.IsNullOrEmpty(model.OldPassword)) { throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Det gamla lösenordet kan inte vara tomt."); } if (string.IsNullOrEmpty(model.NewPassword)) { throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Det nya lösenordet kan inte vara tomt."); } var user = _accessTokenRepository.GetUser(model.UserId.Value); if (user == null) { throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Användare finns inte."); } var userByIdAndPassword = _accessTokenRepository.GetUserByIdAndPassword(model.UserId.Value, _cryptoGraphy.EncryptString(model.OldPassword)); if (userByIdAndPassword == null) { throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Det gamla lösenordet matchar inte det befintliga lösenordet."); } userByIdAndPassword.Password = _cryptoGraphy.EncryptString(model.NewPassword); userByIdAndPassword.ModifiedDate = DateTime.Now; return(_accessTokenRepository.UpdateUseroldPasswordToNewPassword(userByIdAndPassword)); }