public async Task <ActionResult> EditUserName(EditUserNameViewModel model) { ApplicationUser user = await UserManager.FindByNameAsync(User.Identity.Name); if (user != null) { user.UserName = model.Username; IdentityResult result = await UserManager.UpdateAsync(user); if (result.Succeeded) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Щось пішло не так."); } } else { ModelState.AddModelError("", "Користувача не знайдено."); } return(View(model)); }
public ActionResult EditUserName([Bind(Include = "UserName")] EditUserNameViewModel editUserName) { if (!ModelState.IsValid) { return(View(editUserName)); } return(RedirectToAction("Index")); }
public async Task <ActionResult> UpdateName() { ApplicationUser user = db.Users.Find(User.Identity.GetUserId()); EditUserNameViewModel model = new EditUserNameViewModel() { UserID = user.Id, FirstName = user.FirstName ?? "Error", LastName = user.LastName ?? "Error" }; await this.FillViewBag(); return(View(model)); }
public async Task <ActionResult> EditUserName() { ApplicationUser user = await UserManager.FindByNameAsync(User.Identity.Name); if (user != null) { EditUserNameViewModel model = new EditUserNameViewModel { Username = user.UserName }; return(View(model)); } return(RedirectToAction("Index", "Manage")); }
public async Task<ActionResult> EditUserName (EditUserNameViewModel model) { ApplicationUser user = await UserManager.FindByNameAsync(User.Identity.Name); if (user != null) { user.UserName = model.Username; IdentityResult result = await UserManager.UpdateAsync(user); if (result.Succeeded) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "Щось пішло не так."); } } else { ModelState.AddModelError("", "Користувача не знайдено."); } return View(model); }
public async Task<ActionResult> EditUserName() { ApplicationUser user = await UserManager.FindByNameAsync(User.Identity.Name); if (user != null) { EditUserNameViewModel model = new EditUserNameViewModel { Username = user.UserName}; return View(model); } return RedirectToAction("Index", "Manage"); }