public ActionResult OrganizeTreeJson(string postId) { var existAuthorizeData = permissionBLL.GetAuthorizeDataList(postId).ToList(); var organizedata = organizeBLL.GetOrganizeList().ToList(); var departmentdata = departmentBLL.GetDepartmentList().ToList(); var treeList = new List <TreeEntity>(); foreach (OrganizeEntity item in organizedata) { TreeEntity tree = new TreeEntity(); bool hasChildren = organizedata.Count(t => t.ParentId == item.Id) != 0; if (hasChildren == false) { hasChildren = departmentdata.Count(t => t.OrganizeId == item.Id) != 0; if (hasChildren == false) { continue; } } tree.id = item.Id; tree.text = item.FullName; tree.value = item.Id; tree.parentId = item.ParentId; if (item.ParentId == "0") { tree.img = "fa fa-sitemap"; } else { tree.img = "fa fa-home"; } tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.Id); tree.showcheck = true; tree.isexpand = true; tree.complete = true; tree.hasChildren = hasChildren; treeList.Add(tree); } foreach (DepartmentEntity item in departmentdata) { TreeEntity tree = new TreeEntity(); bool hasChildren = departmentdata.Count(t => t.ParentId == item.Id) != 0; tree.id = item.Id; tree.text = item.FullName; tree.value = item.Id; if (item.ParentId == "0") { tree.parentId = item.OrganizeId; } else { tree.parentId = item.ParentId; } tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.Id); tree.showcheck = true; tree.isexpand = true; tree.complete = true; tree.img = "fa fa-umbrella"; tree.hasChildren = hasChildren; treeList.Add(tree); } int authorizeType = -1; if (existAuthorizeData.ToList().Count > 0) { authorizeType = existAuthorizeData.ToList()[0].AuthorizeType.ToInt(); } var jsonData = new { authorizeType = authorizeType, authorizeData = existAuthorizeData, treeJson = treeList.TreeToJson(), }; return(Content(jsonData.TryToJson())); }
public ActionResult OrganizeTreeJson(string userGroupId) { var existAuthorizeData = permissionBLL.GetAuthorizeDataList(userGroupId); var organizedata = organizeBLL.GetList(); var departmentdata = CacheFactory.Cache().GetCache <IEnumerable <DepartmentEntity> >(departmentBLL.cacheKey); //departmentCache.GetList(roleEntity.OrganizeId); if (departmentdata == null) { departmentdata = departmentBLL.GetList(); } var treeList = new List <TreeEntity>(); foreach (OrganizeEntity item in organizedata) { TreeEntity tree = new TreeEntity(); bool hasChildren = organizedata.Count(t => t.ParentId == item.OrganizeId) == 0 ? false : true; if (hasChildren == false) { hasChildren = departmentdata.Count(t => t.OrganizeId == item.OrganizeId) == 0 ? false : true; if (hasChildren == false) { continue; } } tree.id = item.OrganizeId; tree.text = item.FullName; tree.value = item.OrganizeId; tree.parentId = item.ParentId; if (item.ParentId == "0") { tree.img = "fa fa-sitemap"; } else { tree.img = "fa fa-home"; } tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.OrganizeId); tree.showcheck = true; tree.isexpand = true; tree.complete = true; tree.hasChildren = hasChildren; treeList.Add(tree); } foreach (DepartmentEntity item in departmentdata) { TreeEntity tree = new TreeEntity(); bool hasChildren = departmentdata.Count(t => t.ParentId == item.DepartmentId) == 0 ? false : true; tree.id = item.DepartmentId; tree.text = item.FullName; tree.value = item.DepartmentId; if (item.ParentId == "0") { tree.parentId = item.OrganizeId; } else { tree.parentId = item.ParentId; } tree.checkstate = existAuthorizeData.Count(t => t.ResourceId == item.DepartmentId); tree.showcheck = true; tree.isexpand = true; tree.complete = true; tree.img = "fa fa-umbrella"; tree.hasChildren = hasChildren; treeList.Add(tree); } int authorizeType = -1; if (existAuthorizeData.ToList().Count > 0) { authorizeType = existAuthorizeData.ToList()[0].AuthorizeType.ToInt(); } var JsonData = new { authorizeType = authorizeType, authorizeData = existAuthorizeData, treeJson = treeList.TreeToJson(), }; return(Content(JsonData.ToJson())); }