public ActionResult EditProfile(EditProfileViewModel model) { ApplicationDbContext db = new ApplicationDbContext(); if (!ModelState.IsValid) { return View(model); } var user = db.Users.Find(User.Identity.GetUserId()); var existingUser = db.Users.Where(u => u.Email == model.Email).FirstOrDefault(); if (existingUser == null) { user.FirstName = model.FirstName; user.LastName = model.LastName; user.Email = model.Email; user.UserName = model.Email; db.SaveChanges(); AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); return RedirectToAction("LoginNewUsername", "Home"); } else { existingUser.FirstName = model.FirstName; existingUser.LastName = model.LastName; //user.Email = model.Email; //user.UserName = model.Email; db.SaveChanges(); return RedirectToAction("Index", new { Message = ManageMessageId.EditProfileFailed }); } //return RedirectToAction("Index", new { Message = ManageMessageId.EditProfileSuccess }); }
public ActionResult EditProfile() { var name = new EditProfileViewModel(); var user = db.Users.Find(User.Identity.GetUserId()); name.FirstName = user.FirstName; name.LastName = user.LastName; name.Email = user.Email; return View(name); }