Exemple #1
0
        public ActionResult AddRole(RoleAndRloeValues roleAndRoleVal)
        {
            var result = ResModelFactory.ResDefault();

            try
            {
                //添加Role
                SystemRole role = new SystemRole();
                role.ID          = Guid.NewGuid().ToString();
                role.RoleName    = roleAndRoleVal.RoleName;
                role.Description = roleAndRoleVal.Description;
                role.RoleType    = 2;//超管角色只有1个,系统设定

                //添加角色权限
                List <SystemRoleValue> rolevalues = new List <SystemRoleValue>();
                foreach (var rval in roleAndRoleVal.TreeData)
                {
                    SystemRoleValue roleval = new SystemRoleValue();
                    roleval.ID     = Guid.NewGuid().ToString();
                    roleval.RoleId = role.ID;
                    roleval.MenuId = rval.id;
                    roleval.Action = "View,Show,Add,Modify,Delete";
                    rolevalues.Add(roleval);
                    InitRoleVal(rolevalues, rval.children ?? new List <TreeDataViewModel>().ToArray(), role.ID);
                }

                //添加角色,角色权限
                SystemRoleService service = new SystemRoleService();
                service.AddRoleAndRoleVal(role, rolevalues);
            }
            catch (Exception ex)
            {
                result = ResModelFactory.ResError(ex.Message);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }