public IActionResult AdminEdit(AdminAdminNewViewModel vm) { if (IsLogedIn() == true) { if (ModelState.IsValid) { Admin data = vm.Admin; Admin up = _context.Admins.Where(a => a.Id == data.Id).FirstOrDefault(); up.Password = data.Password; up.Email = data.Email; up.Role_Id = data.Role_Id; up.DateModify = data.DateModify; _context.SaveChanges(); } return(View( new AdminAdminNewViewModel() { Admin = _context.Admins.Where(a => a.Id == vm.Admin.Id).FirstOrDefault(), Roles = _context.Roles.OrderBy(r => r.Name) })); } else { return(RedirectToAction("Login")); } }
public IActionResult AdminNew(AdminAdminNewViewModel vm) { if (IsLogedIn() == true) { if (ModelState.IsValid) { _context.Admins.Add(vm.Admin); _context.SaveChanges(); return(RedirectToAction("AdminsOverview")); } else { return(View(new AdminAdminNewViewModel() { Admin = vm.Admin, Roles = _context.Roles.OrderBy(r => r.Name) })); } } else { return(RedirectToAction("Login")); } }