Esempio n. 1
0
        //添加权限
        public IActionResult ModifyRoleRight()
        {
            //展示页面
            if (!Request.Method.ToUpper().Equals("POST", StringComparison.OrdinalIgnoreCase) || !Request.HasFormContentType)
            {
                // 权限和菜单
                ModifyRoleRightModel model = new ModifyRoleRightModel();
                var layoutModel            = this.GetLayoutModel();
                if (layoutModel != null)
                {
                    layoutModel.ToT(ref model);
                }

                int id = 0;
                int.TryParse(Request.Query["id"], out id);

                if (id > 0)
                {
                    var role = CMSAdminBO.GetRoleByID(id);
                    if (role != null && role.ID > 0)
                    {
                        model.Role = role;

                        var modules = CMSAdminBO.GetModules(1);
                        if (modules != null)
                        {
                            model.Modules = modules.ToList();
                        }

                        var roleRights = CMSAdminBO.GetRoleRights(role.ID);
                        if (roleRights != null)
                        {
                            model.RoleModuleIDs = roleRights.Select(s => s.ModuleID).ToList();
                        }
                    }
                }

                return(View(model));
            }
            else
            {
                var msg = new Message(10, "分配失败!");

                int roleID = 0;
                int.TryParse(Request.Form["roleID"], out roleID);

                string[] moduleIDsStr = Request.Form["moduleIDs"];
                var      moduleIDsInt = new List <int>();
                if (moduleIDsStr != null && moduleIDsStr.Count() > 0)
                {
                    foreach (var moduleID in moduleIDsStr)
                    {
                        if (Validator.IsNumbers(moduleID))
                        {
                            moduleIDsInt.Add(int.Parse(moduleID));
                        }
                    }
                }

                if (roleID > 0 && moduleIDsInt != null && moduleIDsInt.Count() > 0)
                {
                    msg = CMSAdminBO.CreateRoleRight(roleID, moduleIDsInt);
                }

                return(new JsonResult(msg));
            }
        }