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

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

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

                if (id > 0)
                {
                    model.PageTitle = "修改菜单";
                    var module = CMSAdminBO.GetModule(id);
                    if (module != null && module.ID > 0)
                    {
                        model.Module = module;
                    }
                }
                else
                {
                    model.PageTitle = "添加菜单";
                }

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

                int id = 0;
                int.TryParse(Request.Form["id"], out id);
                int parentID = 0;
                int.TryParse(Request.Form["parentID"], out parentID);
                string title      = Request.Form["title"];
                string controller = Request.Form["controller"];
                string action     = Request.Form["action"];
                int    sort       = 0;
                int.TryParse(Request.Form["sort"], out sort);
                byte state = 1;
                byte.TryParse(Request.Form["state"], out state);

                var module = new Module()
                {
                    ID         = id,
                    ParentID   = parentID,
                    Title      = title,
                    Controller = controller,
                    Action     = action,
                    Sort       = sort,
                    State      = state
                };

                if (module.ID > 0)
                {
                    msg = CMSAdminBO.UpdateModule(module);
                }
                else
                {
                    msg = CMSAdminBO.CreateModule(module);
                }

                return(new JsonResult(msg));
            }
        }
Example #2
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));
            }
        }
Example #3
0
        //菜单管理
        public IActionResult ModuleList(string id)
        {
            if (id == null || !id.ToUpper().Equals("DATA", StringComparison.OrdinalIgnoreCase))
            {
                // 权限和菜单
                ModuleListModel model       = new ModuleListModel();
                var             layoutModel = this.GetLayoutModel();
                if (layoutModel != null)
                {
                    layoutModel.ToT(ref model);
                }

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

                return(View(model));
            }
            else
            {
                //取菜单列表
                string titleFilter = Request.Query["title"];

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

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

                int pageLimit = Consts.Page_Limit;
                int totCount  = CMSAdminBO.GetModuleCount(titleFilter, parentIDFilter);
                int pageCount = (int)Math.Ceiling(totCount / (float)pageLimit);
                var modules   = new List <Module>();
                if (totCount > 0)
                {
                    IEnumerable <Module> moduleIE = CMSAdminBO.GetModules(titleFilter, parentIDFilter, pageLimit, pageIndex);
                    if (moduleIE != null)
                    {
                        modules = moduleIE.ToList();
                    }
                }

                dynamic model = new ExpandoObject();

                model.code  = 0;
                model.msg   = "";
                model.count = totCount;
                model.data  = modules.Select(s => new
                {
                    id          = s.ID,
                    title       = s.Title,
                    parentTitle = s.ParentTitle,
                    controller  = s.Controller,
                    action      = s.Action,
                    state       = s.State
                });

                return(new JsonResult(model));
            }
        }