public async Task <IActionResult> ChangeCredentials([FromBody] ChangeCredentialsViewModel model) { ChangeCredentials changeCredentials = new ChangeCredentials(); if (ModelState.IsValid) { UserInformation userInformation = new UserInformation(); FairfieldAllergeryRepository fairfieldAllergeryRepository = new FairfieldAllergeryRepository(); try { var result = await signInManager.PasswordSignInAsync( model.OldUserName, model.OldPassword, true, false); //If signin works if (result.Succeeded) { //Check to see if user llready exists if (fairfieldAllergeryRepository.CheckToSeeIfIdIsAlreadyUsed(model.UserName)) { var user = await userManager.FindByNameAsync(model.OldUserName); var checkPassword = await signInManager.CheckPasswordSignInAsync(user, model.OldPassword, true); if (checkPassword.Succeeded) { var token = await userManager.GeneratePasswordResetTokenAsync(user); if (user != null) { var passwordChangeResult = await userManager.ResetPasswordAsync(user, token, model.Password); if (passwordChangeResult.Succeeded) { //if (await userManager.IsLockedOutAsync(user)) //{ // await userManager.SetLockoutEndDateAsync(user, DateTimeOffset.UtcNow); //} fairfieldAllergeryRepository.UpdateUseridAndPassword(model); } else { userInformation = fairfieldAllergeryRepository.GetUserInformation(model.UserName); userInformation.Status = "Failure"; userInformation.ErrorMessage = "Password change did not succeed"; return(Ok(userInformation)); } } else { userInformation = fairfieldAllergeryRepository.GetUserInformation(model.UserName); userInformation.Status = "Failure"; userInformation.ErrorMessage = "User is null"; return(Ok(userInformation)); } } else { userInformation = fairfieldAllergeryRepository.GetUserInformation(model.UserName); userInformation.Status = "Failure"; userInformation.ErrorMessage = "Password check failed"; return(Ok(userInformation)); } } else { userInformation = fairfieldAllergeryRepository.GetUserInformation(model.UserName); userInformation.Status = "Failure"; userInformation.ErrorMessage = "UserId already taken. Please select another"; return(Ok(userInformation)); } //*************************************************************************************************** if (fairfieldAllergeryRepository.HasUserChangedIdAndPassword(model.UserName)) { userInformation = fairfieldAllergeryRepository.GetUserInformation(model.UserName); userInformation.Status = "Success"; return(Ok(userInformation)); } else { userInformation = fairfieldAllergeryRepository.GetUserInformation(model.UserName); userInformation.Status = "Change"; return(Ok(userInformation)); } } else { changeCredentials.Status = "Failure"; changeCredentials.ErrorMessage = "None"; userInformation = fairfieldAllergeryRepository.GetUserInformation(model.UserName); return(Ok(userInformation)); return(Ok(changeCredentials)); } } catch (Exception ex) { string s1 = ex.ToString(); } } changeCredentials.Status = "Failure"; changeCredentials.ErrorMessage = "None"; return(Ok(changeCredentials)); }