public ActionResult Edit(string id) { if (User.Identity.GetUserId() == id || User.IsInRole("SuperAdmin") || User.IsInRole("Admin")) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ApplicationUsersVM applicationUsersVM = new ApplicationUsersVM() { ApplicationUser = db.Users.Find(id), ListEcolesDispo = db.Ecoles.ToList(), ListRolesDispo = db.Role.ToList() }; if (applicationUsersVM.ApplicationUser == null) { return(HttpNotFound()); } if (applicationUsersVM.ApplicationUser.Ecole != null) { applicationUsersVM.IdEcoleSelected = applicationUsersVM.ApplicationUser.Ecole.Id; } return(View(applicationUsersVM)); } return(Edit(User.Identity.GetUserId())); }
public ActionResult Edit(ApplicationUsersVM applicationUsersVM) { ApplicationUser user = db.Users.FirstOrDefault(u => u.Id == applicationUsersVM.ApplicationUser.Id); user.Ecole = db.Ecoles.FirstOrDefault(e => e.Id == applicationUsersVM.IdEcoleSelected); user.Email = applicationUsersVM.ApplicationUser.Email; user.UserName = applicationUsersVM.ApplicationUser.Email; if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }