public ActionResult EditUser(ManagementEditUserViewModel model) { if (!ModelState.IsValid) { ModelState.AddModelError("", "Model validation Error"); return View(model); } if (Roles.IsUserInRole(User.Identity.Name, "Developer")) { Account userAccount = new Account { Email = model.Email, //we are gonna use RegistrationDate to deliver the new email RegistrationDate = model.NewEmail, LastName = model.LastName, FirstName = model.FirstName, BirthDate = model.BirthDate, Gender = model.Gender, PhoneNumber = model.PhoneNumber, Password = model.Password, }; UserManagerResult updateUserResult = UserManager.EditUser(User.Identity.Name, userAccount, model.ManagementPassword); if (updateUserResult.ErrorMessage != null) { ModelState.AddModelError("", updateUserResult.ErrorMessage); model.Password = ""; model.ConfirmPassword = ""; model.ManagementPassword = ""; return View(model); } if (updateUserResult.Success) { if (User.Identity.Name == model.Email) { return RedirectToAction("LogOut", "Account"); } TempData["UserUpdated"] = "User updated successfully"; return RedirectToAction("Index", "Management"); } ModelState.AddModelError("", "Wrong Management password"); return View(model); } return RedirectToAction("index", "Home"); }
public ActionResult EditUser(string email) { if (Roles.IsUserInRole(User.Identity.Name, "Developer")) { ManagementEditUserViewModel model = new ManagementEditUserViewModel(); UserManagerResult getUserResult = UserManager.GetUser(email); if (!getUserResult.Success) { ModelState.AddModelError("", "Some Thing went wrong"); return View(model); } model.Email = getUserResult.User.Email.Replace(" ", String.Empty); model.LastName = getUserResult.User.LastName.Replace(" ", String.Empty); model.FirstName = getUserResult.User.FirstName.Replace(" ", String.Empty); model.BirthDate = getUserResult.User.BirthDate.Replace(" ", String.Empty); model.Gender = getUserResult.User.Gender.Replace(" ", String.Empty); model.PhoneNumber = getUserResult.User.PhoneNumber; return View(model); } return RedirectToAction("Index", "Home"); //return View(model); }