using NFine.Application.SystemManage; using NFine.Code; using NFine.Domain.Entity.SystemManage; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; namespace NFine.Web.Areas.SystemManage.Controllers { public class RoleAuthorizeController : ControllerBase { private RoleAuthorizeApp roleAuthorizeApp = new RoleAuthorizeApp(); private ModuleApp moduleApp = new ModuleApp(); private ModuleButtonApp moduleButtonApp = new ModuleButtonApp(); private FormDataActionApp formDataActionApp = new FormDataActionApp(); public ActionResult GetPermissionTree(string roleId) { var moduledata = moduleApp.GetListALL(); var buttondata = moduleButtonApp.GetList(); var authorizedata = new List(); if (!string.IsNullOrEmpty(roleId)) { authorizedata = roleAuthorizeApp.GetList(roleId); } var treeList = new List(); foreach (ModuleEntity item in moduledata) { TreeViewModel tree = new TreeViewModel(); bool hasChildren = moduledata.Count(t => t.F_ParentId == item.F_Id) == 0 ? false : true; tree.id = item.F_Id; tree.text = item.F_FullName; tree.value = item.F_EnCode; tree.parentId = item.F_ParentId; tree.isexpand = true; tree.complete = true; tree.showcheck = true; tree.checkstate = authorizedata.Count(t => t.F_ItemId == item.F_Id); tree.hasChildren = true; tree.img = item.F_Icon == "" ? "" : item.F_Icon; treeList.Add(tree); } foreach (ModuleButtonEntity item in buttondata) { TreeViewModel tree = new TreeViewModel(); bool hasChildren = buttondata.Count(t => t.F_ParentId == item.F_Id) == 0 ? false : true; tree.id = item.F_Id; tree.text = item.F_FullName; tree.value = item.F_EnCode; tree.parentId = item.F_ParentId == "0" ? item.F_ModuleId : item.F_ParentId; tree.isexpand = true; tree.complete = true; tree.showcheck = true; tree.checkstate = authorizedata.Count(t => t.F_ItemId == item.F_Id); tree.hasChildren = hasChildren; tree.img = item.F_Icon == "" ? "" : item.F_Icon; treeList.Add(tree); } return Content(treeList.TreeViewJson()); } public ActionResult GetDataActionTree(string roleId) { var moduledata = moduleApp.GetListALL(); var dataaction = formDataActionApp.GetList(); var dataActiondata = new List(); if (!string.IsNullOrEmpty(roleId)) { dataActiondata = formDataActionApp.GetRoleDataList(roleId); } var treeList = new List(); foreach (ModuleEntity item in moduledata) { TreeViewModel tree = new TreeViewModel(); bool hasChildren = moduledata.Count(t => t.F_ParentId == item.F_Id) == 0 ? false : true; tree.id = item.F_Id; tree.text = item.F_FullName; tree.value = item.F_EnCode; tree.parentId = item.F_ParentId; tree.isexpand = true; tree.complete = true; tree.showcheck = true; tree.checkstate = dataActiondata.Count(t => t.DataActionId == item.F_Id); tree.hasChildren = true; tree.img = item.F_Icon == "" ? "" : item.F_Icon; treeList.Add(tree); } foreach (FormDataActionEntity item in dataaction) { TreeViewModel tree = new TreeViewModel(); tree.id = item.ID; tree.text = item.CFiledName; tree.value = item.CCaption; tree.parentId = item.SourceId; tree.isexpand = true; tree.complete = true; tree.showcheck = true; tree.checkstate = dataActiondata.Count(t => t.DataActionId == item.ID); tree.hasChildren = false; tree.img = ""; treeList.Add(tree); } return Content(treeList.DataActionTreeViewJson()); } } }