public async Task <IActionResult> Edit(AdminsEditModel model) { if (!IsUserAuthenticated()) { return(Redirect("/Users/Login")); } if (!IsAdminAndActive()) { return(Redirect("/")); } if (ModelState.IsValid) { User admin = new User { Id = model.Id, Username = model.Username, Password = model.Password, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, PersonalID = model.PersonalID, PhoneNumber = model.PhoneNumber, Email = model.Email, Active = model.Active, Role = model.Role }; try { _context.Update(admin); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdminExists(model.Id)) { return(NotFound()); } else { throw; } } return(Redirect("/Admins/List")); } return(View(model)); }
// GET: Admins/Edit/5 public async Task <IActionResult> Edit(int?id) { if (!IsUserAuthenticated()) { return(Redirect("/Users/Login")); } if (!IsAdminAndActive()) { return(Redirect("/")); } if (id == null) { return(NotFound()); } User admin = await _context.Users.FindAsync(id); if (admin == null) { return(NotFound()); } AdminsEditModel model = new AdminsEditModel { Id = admin.Id, Role = admin.Role, Username = admin.Username, Password = admin.Password, FirstName = admin.FirstName, MiddleName = admin.MiddleName, LastName = admin.LastName, PersonalID = admin.PersonalID, PhoneNumber = admin.PhoneNumber, Email = admin.Email, Active = admin.Active }; return(View(model)); }