示例#1
0
 public IActionResult UpdatePreferences([FromBody] UpdatePreferencesWrapper upPreferences)
 {
     _userService.UpdatePreferences(upPreferences, GetUserIdFromJwtToken());
     return(Ok(new AuthResponse
     {
         Success = true,
         AccessToken = _userService.GenerateAuthToken(_userService.GetById(GetUserIdFromJwtToken())),
         Messages = new string[] { "Settings has been updated." }
     }));
 }
        public void UpdatePreferences(UpdatePreferencesWrapper upPreferences, int userId)
        {
            User user = _unitOfWork.Users.Find <User>(userId);

            user.AuthenticationTime     = Int32.Parse(upPreferences.VerificationTime);
            user.PasswordNotifications  = Int32.Parse(upPreferences.PassNotifications);
            user.TwoFactorAuthorization = Int32.Parse(upPreferences.TwoFactor);
            try
            {
                _unitOfWork.Users.Update <User>(user);
                _unitOfWork.SaveChanges();
            }
            catch (Exception)
            {
                throw new UserServiceException(
                          "There was an error during update. Try again or contact support.");
            }
        }