public AdminTree GetTree(int?id)
        {
            AdminTree adminTree = new AdminTree {
                RootContoller = "Webpage"
            };
            IQueryOver <Webpage, Webpage> query = _session.QueryOver <Webpage>().Where(x => x.Parent.Id == id);
            int maxChildNodes = 1000;

            if (id.HasValue)
            {
                Webpage parent = _session.Get <Webpage>(id);
                if (parent != null)
                {
                    DocumentMetadata metaData = parent.GetMetadata();
                    maxChildNodes = metaData.MaxChildNodes;
                    query         = ApplySort(metaData, query);
                }
            }
            else
            {
                adminTree.IsRootRequest = true;
                query = query.OrderBy(x => x.DisplayOrder).Asc;
            }

            int rowCount = query.Cacheable().RowCount();

            query.Take(maxChildNodes).Cacheable().List().ForEach(doc =>
            {
                DocumentMetadata documentMetadata = doc.GetMetadata();
                AdminTreeNode node = new AdminTreeNode
                {
                    Id                 = doc.Id,
                    ParentId           = doc.ParentId,
                    Name               = doc.Name,
                    IconClass          = documentMetadata.IconClass,
                    NodeType           = "Webpage",
                    Type               = documentMetadata.Type.FullName,
                    HasChildren        = _treeNavService.GetWebpageNodes(doc.Id).Nodes.Any(),
                    Sortable           = documentMetadata.Sortable,
                    CanAddChild        = _validWebpageChildrenService.AnyValidWebpageDocumentTypes(doc),
                    IsPublished        = doc.Published,
                    RevealInNavigation = doc.RevealInNavigation,
                    Url                = _urlHelper.Action("Edit", "Webpage", new { id = doc.Id })
                };
                adminTree.Nodes.Add(node);
            });
            if (rowCount > maxChildNodes)
            {
                adminTree.Nodes.Add(new AdminTreeNode
                {
                    IconClass  = "glyphicon glyphicon-plus",
                    IsMoreLink = true,
                    ParentId   = id,
                    Name       = (rowCount - maxChildNodes) + " More",
                    Url        = _urlHelper.Action("Search", "WebpageSearch", new { parentId = id }),
                });
            }
            return(adminTree);
        }
        public AdminTree GetTree(int?id)
        {
            Webpage parent    = id.HasValue ? _session.Get <Webpage>(id) : null;
            var     adminTree = new AdminTree
            {
                RootContoller = "Webpage",
                IsRootRequest = parent == null
            };
            int maxChildNodes = parent == null ? 1000 : parent.GetMetadata().MaxChildNodes;
            IQueryOver <Webpage, Webpage> query = GetQuery(parent);

            int rowCount = GetRowCount(query);

            query.Take(maxChildNodes).Cacheable().List().ForEach(doc =>
            {
                DocumentMetadata documentMetadata = doc.GetMetadata();
                var node = new AdminTreeNode
                {
                    Id                 = doc.Id,
                    ParentId           = doc.ParentId,
                    Name               = doc.Name,
                    IconClass          = documentMetadata.IconClass,
                    NodeType           = "Webpage",
                    Type               = documentMetadata.Type.FullName,
                    HasChildren        = _treeNavService.WebpageHasChildren(doc.Id),
                    Sortable           = documentMetadata.Sortable,
                    CanAddChild        = _validWebpageChildrenService.AnyValidWebpageDocumentTypes(doc),
                    IsPublished        = doc.Published,
                    RevealInNavigation = doc.RevealInNavigation,
                    Url                = _urlHelper.Action("Edit", "Webpage", new { id = doc.Id })
                };
                adminTree.Nodes.Add(node);
            });
            if (rowCount > maxChildNodes)
            {
                adminTree.Nodes.Add(new AdminTreeNode
                {
                    IconClass  = "glyphicon glyphicon-plus",
                    IsMoreLink = true,
                    ParentId   = id,
                    Name       = (rowCount - maxChildNodes) + " More",
                    Url        = _urlHelper.Action("Search", "WebpageSearch", new { parentId = id }),
                });
            }
            return(adminTree);
        }
Пример #3
0
        private AdminTree GetSimpleAdminTree <T>(int?id, string iconClass) where T : Document
        {
            AdminTree adminTree = new AdminTree();

            if (!id.HasValue)
            {
                adminTree.IsRootRequest = true;
            }
            IList <T> query =
                _session.QueryOver <T>()
                .Where(x => x.Parent.Id == id && (x.HideInAdminNav == false || x.HideInAdminNav == null))
                .OrderBy(x => x.Name)
                .Asc.Cacheable()
                .List();

            query.ForEach(doc =>
            {
                Type type          = typeof(T);
                AdminTreeNode node = new AdminTreeNode
                {
                    Id                 = doc.Id,
                    ParentId           = doc.ParentId,
                    Name               = doc.Name,
                    IconClass          = iconClass,
                    NodeType           = type.Name,
                    Type               = type.FullName,
                    HasChildren        = _session.QueryOver <T>().Where(arg => arg.Parent.Id == doc.Id).Cacheable().Any(),
                    CanAddChild        = true,
                    IsPublished        = true,
                    RevealInNavigation = true,
                    Url                = _urlHelper.Action(typeof(T) == typeof(Layout) ? "Edit" : "Show", type.Name, new { id = doc.Id })
                };
                adminTree.Nodes.Add(node);
            });
            return(adminTree);
        }