/// <summary> /// Builds the model. /// </summary> /// <param name="helper">The helper.</param> /// <param name="startingNode">The starting node.</param> /// <returns>The model.</returns> private static SitemapHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode) { // Build model var model = new SitemapHelperModel(); var node = startingNode; while (node != null) { var mvcNode = node as MvcSiteMapNode; // Check visibility bool nodeVisible = true; if (mvcNode != null) { nodeVisible = mvcNode.VisibilityProvider.IsVisible( node, HttpContext.Current, BreadcrumbSourceMetadata); } // Check ACL if (nodeVisible && node.IsAccessibleToUser(HttpContext.Current)) { // Add node var nodeToAdd = SiteMapNodeModelMapper.MapToSiteMapNodeModel(node, mvcNode, BreadcrumbSourceMetadata); model.Nodes.Add(nodeToAdd); } node = node.ParentNode; } model.Nodes.Reverse(); return(model); }
public static SiteMapNodeModel GetNodeByKey(this MvcSiteMapHtmlHelper helper, string nodeKey) { SiteMapNode node = helper.Provider.FindSiteMapNodeFromKey(nodeKey); var mvcNode = node as MvcSiteMapNode; var mvcNodeModel = SiteMapNodeModelMapper.MapToSiteMapNodeModel(node, mvcNode, SourceMetadata); return(mvcNodeModel); }
/// <summary> /// Builds the model. /// </summary> /// <param name="helper">The helper.</param> /// <param name="startingNode">The starting node.</param> /// <param name="startingNodeInChildLevel">Renders startingNode in child level if set to <c>true</c>.</param> /// <param name="showStartingNode">Show starting node if set to <c>true</c>.</param> /// <param name="maxDepth">The max depth.</param> /// <param name="drillDownToCurrent">Should the model exceed the maxDepth to reach the current node</param> /// <returns>The model.</returns> private static SitemapHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth, bool drillDownToCurrent) { // Build model var model = new SitemapHelperModel(); var node = startingNode; // Check if a starting node has been given if (node == null) { return(model); } var mvcNode = node as MvcSiteMapNode; bool continueBuilding = ReachedMaximalNodelevel(maxDepth, node, drillDownToCurrent); // Check if maximal node level has not been reached if (!continueBuilding) { return(model); } // Check visibility bool nodeVisible = true; if (mvcNode != null) { nodeVisible = mvcNode.VisibilityProvider.IsVisible( node, HttpContext.Current, TabsSourceMetadata); } // Check ACL if (node.IsAccessibleToUser(HttpContext.Current)) { // Add node? var nodeToAdd = SiteMapNodeModelMapper.MapToSiteMapNodeModel(node, mvcNode, TabsSourceMetadata); if (nodeVisible) { if (showStartingNode || !startingNodeInChildLevel) { model.Nodes.Add(nodeToAdd); } } // Add child nodes if (node.HasChildNodes) { foreach (SiteMapNode childNode in node.ChildNodes) { var childNodes = BuildModel(helper, childNode, false, true, maxDepth - 1, drillDownToCurrent).Nodes; foreach (var childNodeToAdd in childNodes) { if (!startingNodeInChildLevel) { nodeToAdd.Children.Add(childNodeToAdd); } else { model.Nodes.Add(childNodeToAdd); } } } } } return(model); }