public async Task<ActionResult> Profile(ProfileUserViewModel model) { if (ModelState.IsValid) { ApplicationUser user = UserManager.FindById(User.Identity.GetUserId()); if (user != null) { user.UserExtentLogin.FullName = model.FullName; user.UserExtentLogin.Email = model.Email; user.UserExtentLogin.BirthDate = model.BirthDay; user.UserExtentLogin.Status = model.Status; } else { return RedirectToAction("Login"); } IdentityResult result = await UserManager.UpdateAsync(user); if (result.Succeeded) { return RedirectToAction("Profile", new { Message = ManageMessageId.UpdateSucess }); } else { AddErrors(result); } } return View(model); }
public ActionResult Profile(ManageMessageId? message) { ViewBag.StatusMessage = message == ManageMessageId.UpdateSucess ? "Cập nhật tài khoản thành công." : ""; ProfileUserViewModel profile = new ProfileUserViewModel(); ApplicationUser user = UserManager.FindById(User.Identity.GetUserId()); if (user == null) // if session of user has expire { return RedirectToAction("Login"); } else // user not null { profile.UserName = user.UserName; profile.FullName = user.UserExtentLogin.FullName; profile.Email = user.UserExtentLogin.Email; profile.BirthDay = user.UserExtentLogin.BirthDate; profile.CreatedDate = user.UserExtentLogin.CreatedDate.ToString("dd/MM/yyyy"); profile.Verify = user.UserExtentLogin.Verify;//== null? Verify.NO: Verify.YES; profile.Status = user.UserExtentLogin.Status; } ViewBag.ImageUrl = ImageURLAvata + user.UserExtentLogin.AvataImage; ViewBag.ImageUrlCover = ImageURLCover + user.UserExtentLogin.AvataCover; return View(profile); }