/// <summary> /// Builds the model. /// </summary> /// <param name="helper">The helper.</param> /// <param name="startingNode">The starting node.</param> /// <returns>The model.</returns> private static SiteMapPathHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode) { // Build model var model = new SiteMapPathHelperModel(); 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, SourceMetadata); } // Check ACL if (nodeVisible && node.IsAccessibleToUser(HttpContext.Current)) { // Add node var nodeToAdd = SiteMapNodeModelMapper.MapToSiteMapNodeModel(node, mvcNode, SourceMetadata); model.Nodes.Add(nodeToAdd); } node = node.ParentNode; } model.Nodes.Reverse(); return(model); }
/// <summary> /// Builds the model. /// </summary> /// <param name="startingNode">The starting node.</param> /// <returns>The model.</returns> private static SiteMapTitleHelperModel BuildModel(SiteMapNode startingNode) { // Map to model var mvcNode = startingNode as MvcSiteMapNode; return(new SiteMapTitleHelperModel { CurrentNode = SiteMapNodeModelMapper.MapToSiteMapNodeModel(startingNode, mvcNode, SourceMetadata) }); }
/// <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> /// <returns>The model.</returns> private static SiteMapHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, bool startingNodeInChildLevel) { // Build model var model = new SiteMapHelperModel(); var node = startingNode; var mvcNode = node as MvcSiteMapNode; // Check visibility bool nodeVisible = true; if (mvcNode != null) { nodeVisible = mvcNode.VisibilityProvider.IsVisible( node, HttpContext.Current, SourceMetadata); } // Check ACL if (nodeVisible && node.IsAccessibleToUser(HttpContext.Current)) { // Add node var nodeToAdd = SiteMapNodeModelMapper.MapToSiteMapNodeModel(node, mvcNode, SourceMetadata); model.Nodes.Add(nodeToAdd); // Add child nodes if (node.HasChildNodes) { foreach (SiteMapNode childNode in node.ChildNodes) { foreach (var childNodeToAdd in BuildModel(helper, childNode, false).Nodes) { if (!startingNodeInChildLevel) { nodeToAdd.Children.Add(childNodeToAdd); } else { model.Nodes.Add(childNodeToAdd); } } } } } return(model); }
/// <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 MenuHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth, bool drillDownToCurrent = false) #endif { // Build model var model = new MenuHelperModel(); 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, SourceMetadata); } // Check ACL if (node.IsAccessibleToUser(HttpContext.Current)) { // Add node? var nodeToAdd = SiteMapNodeModelMapper.MapToSiteMapNodeModel(node, mvcNode, SourceMetadata); 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); }