Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
 public ActionResult Index()
 {
     var vm = new RolesViewModel(UserManagementRepository);
     return View("Index", vm);
 }