Exemple #1
0
 public static bool IsParentsActive(SiteMapItem siteNode)
 {
     if (siteNode != null)
     {
         return siteNode.IsActive && IsParentsActive(siteNode.ParentNode);
     }
     return true;
 }
Exemple #2
0
 private IEnumerable<SiteMapItem> GetChildsRecursively(IEnumerable<Page> pages, SiteMapItem parent)
 {
     var childs = new List<SiteMapItem>();
     IEnumerable<Page> childPages = pages.Where(p => p.ParentId == parent.Id)
         .OrderBy(p => p.Title).OrderBy(p => p.SortOrder);
     foreach (Page childPage in childPages)
     {
         SiteMapItem child = ConvertToSiteMapItem(childPage, parent);
         child.ChildNodes = GetChildsRecursively(pages, child);
         childs.Add(child);
     }
     return childs;
 }
Exemple #3
0
        private SiteMapItem ConvertToSiteMapItem(Page page, SiteMapItem parent)
        {
            if (page == null)
                throw new ArgumentNullException();

            var siteMapItem = new SiteMapItem
            {
                DisplayOnMainMenu = page.DisplayOnMainMenu,
                DisplayOnSideMenu = page.DisplayOnSideMenu,
                Id = page.Id,
                ParentNode = parent,
                SortOrder = page.SortOrder,
                Title = page.Title,
                Url = page.Url,
                IsActive = page.IsActive
            };
            return siteMapItem;
        }
        private static SideMenuCollectionModel GetLinks(Guid selectedNodeId, SiteMapItem node, Guid childRootId,
		                                                SideMenuCollectionModel childs, bool displayInactive)
        {
            if (node.Layer > 0)
            {
                var collection =
                    new SideMenuCollectionModel(node.ChildNodes
                                                    .Where(n => n.DisplayOnSideMenu && (n.IsActive || displayInactive))
                                                    .Select(n => new SideMenuLinkModel
                                                                 	{
                                                                 		IsCurrent = n.Id == selectedNodeId,
                                                                 		Title = n.Title,
                                                                 		Url = n.Url,
                                                                 		Childs = n.Id == childRootId ? childs : new SideMenuCollectionModel()
                                                                 	}).ToList());
                collection.HasCurrent = node.ChildNodes.Any(n => n.Id == selectedNodeId) || childs.HasCurrent;
                return GetLinks(selectedNodeId, node.ParentNode, node.Id, collection, displayInactive);
            }

            return childs;
        }
 private static SiteMapItem GetRootSectionNode(SiteMapItem node)
 {
     return node.Layer == 1 ? node : GetRootSectionNode(node.ParentNode);
 }