public async Task <IActionResult> UpdateProfile(EditProfile obj) { EidtUserProfileViewModel model = obj.UserProfileVM; if (ModelState.IsValid) { AccountUser user = new AccountUser(); user = await userManager.FindByIdAsync(model.Id); if (user != null) { user.FirstName = model.FName; user.LastName = model.LName; user.Gender = model.Gender; user.AboutMe = model.AboutMe; user.DOB = model.DOB; var res = await userManager.UpdateAsync(user); if (res.Succeeded) { toastNotification.AddSuccessToastMessage("Profile Update successfully"); } else { toastNotification.AddErrorToastMessage("Some issue to update Profile"); ModelState.AddModelError(String.Empty, "Error"); } } } return(RedirectToAction("EditUser", new RouteValueDictionary( new { controller = "Admin", action = "EditUser", UserId = model.Id }))); }
public async Task <IActionResult> UpdateProfile(EditProfile obj) { EidtUserProfileViewModel model = obj.UserProfileVM; if (ModelState.IsValid) { AccountUser user = new AccountUser(); //IF user identity is correct proceed to update if (User.Identity.IsAuthenticated) { user = await userManager.GetUserAsync(User); if (user != null) { user.FirstName = model.FName; user.LastName = model.LName; user.Gender = model.Gender; user.AboutMe = model.AboutMe; user.DOB = model.DOB; var res = await userManager.UpdateAsync(user); if (res.Succeeded) { toastNotification.AddSuccessToastMessage("Profile Update Successfully."); } //GIVE an error if something is wrong else { toastNotification.AddErrorToastMessage("Some issue to updating profile."); ModelState.AddModelError(String.Empty, "Error"); } } } } return(RedirectToAction("EditProfile")); }