Пример #1
0
        public async Task <ActionResult> AddRole(AddEditRoleData data, string submitAction)
        {
            if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.SecurityManagement))
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (submitAction == "cancel")
            {
                return(RedirectToRoute("ManageRoles"));
            }

            if (!ModelState.IsValid)
            {
                await FillAddEditRoleDataAsync(data);

                return(View("~/Views/Admin/AddRole.cshtml", data));
            }

            try
            {
                await SecurityManager.CreateNewRoleAsync(data.RoleEdited.RoleDescription, data.SystemRightsSet, data.AuditActionsSet);
            }
            catch (ORMQueryExecutionException ex)
            {
                ModelState.AddModelError("RoleDescription", "Save failed, likely due to the role description not being unique. Please specify a unique role description name." + ex.Message);
                await FillAddEditRoleDataAsync(data);

                return(View("~/Views/Admin/AddRole.cshtml", data));
            }

            return(View("~/Views/Admin/Roles.cshtml", data));
        }
Пример #2
0
        public async Task <ActionResult> AddRole()
        {
            if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.SecurityManagement))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var data = new AddEditRoleData();

            await FillAddEditRoleDataAsync(data);

            return(View("~/Views/Admin/AddRole.cshtml", data));
        }
Пример #3
0
        public async Task <ActionResult> EditRole(int roleId)
        {
            if (!this.HttpContext.Session.HasSystemActionRights() || !this.HttpContext.Session.HasSystemActionRight(ActionRights.SecurityManagement))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var data = new AddEditRoleData {
                RoleEdited = await SecurityGuiHelper.GetRoleAsync(roleId)
            };

            if (data.RoleEdited == null)
            {
                return(RedirectToRoute("ManageRoles"));
            }

            await FillAddEditRoleDataAsync(data);

            data.SystemRightsSet = SecurityGuiHelper.GetAllSystemActionRightIDsForRole(roleId);
            data.AuditActionsSet = SecurityGuiHelper.GetAllAuditActionIDsForRole(roleId);
            return(View("~/Views/Admin/EditRole.cshtml", data));
        }
Пример #4
0
        private async Task FillAddEditRoleDataAsync(AddEditRoleData data)
        {
            data.AvailableSystemRights = await SecurityGuiHelper.GetAllSystemActionRightsAsync();

            data.AvailableAuditActions = await SecurityGuiHelper.GetAllAuditActionsAsync();
        }