public ActionResult Index(string action, RoleInputModel[] list) { if (action == "new") return Create(); if (action == "delete") return Delete(list); ModelState.AddModelError("", Resources.RoleController.InvalidAction); var vm = new RolesViewModel(UserManagementRepository); return View("Index", vm); }
private ActionResult Delete(RoleInputModel[] list) { var query = from item in list where item.Delete && !(item.CanDelete) select item.Name; foreach(var name in query) { ModelState.AddModelError("", string.Format(Resources.RoleController.CannotDeleteRole, name)); } if (ModelState.IsValid) { try { foreach (var item in list.Where(x=>x.Delete && x.CanDelete).Select(x=>x.Name)) { UserManagementRepository.DeleteRole(item); } TempData["Message"] = Resources.RoleController.RolesDeleted; return RedirectToAction("Index"); } catch (ValidationException ex) { ModelState.AddModelError("", ex.Message); } catch { ModelState.AddModelError("", Resources.RoleController.ErrorDeletingRole); } } var vm = new RolesViewModel(UserManagementRepository); return View("Index", vm); }
public ActionResult Index() { var vm = new RolesViewModel(UserManagementRepository); return View("Index", vm); }
private ActionResult Delete(RoleInputModel[] list) { var query = from item in list where item.Delete && !(item.CanDelete) select item.Name; foreach(var name in query) { ModelState.AddModelError("", "Can't delete role " + name + "."); } if (ModelState.IsValid) { try { foreach (var item in list.Where(x=>x.Delete && x.CanDelete).Select(x=>x.Name)) { UserManagementRepository.DeleteRole(item); } TempData["Message"] = "Roles Deleted"; return RedirectToAction("Index"); } catch (ValidationException ex) { ModelState.AddModelError("", ex.Message); } catch { ModelState.AddModelError("", "Error deleting role."); } } var vm = new RolesViewModel(UserManagementRepository); return View("Index", vm); }