예제 #1
0
 private void PermisssionTreeAddChildren(List <Permission> permissions, PermissionTreeNode node, int index)
 {
     for (var i = index + 1; i < permissions.Count; i++)
     {
         var item = permissions[i];
         if (item.ParentId == node.Id)
         {
             if (node.Children == null)
             {
                 node.Children = new List <PermissionTreeNode>();
             }
             var child = PermissionTreeNodeFromPermisssion(item);
             // 在父节点的 ParentIdPath 基础上增加 ParentId
             child.ParentIdPath = node.ParentIdPath != null ? new List <Guid>(node.ParentIdPath) : new List <Guid>(1);
             child.ParentIdPath.Add(node.Id);
             node.Children.Add(child);
             PermisssionTreeAddChildren(permissions, child, i);
         }
     }
 }
예제 #2
0
        private PermissionTreeNode FindPermissionTreeNode(List <PermissionTreeNode> list, Guid permissionId)
        {
            PermissionTreeNode result = null;

            foreach (var node in list)
            {
                if (node.Id == permissionId)
                {
                    result = node;
                }
                else if (!node.Children.IsNullOrEmpty())
                {
                    result = FindPermissionTreeNode(node.Children, permissionId);
                }
                if (result != null)
                {
                    break;
                }
            }
            return(result);
        }