/// <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 NavHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth, bool drillDownToCurrent) { // Build model var model = new NavHelperModel(); 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, NavSourceMetadata); } // Check ACL if (node.IsAccessibleToUser(HttpContext.Current)) { // Add node? var nodeToAdd = SiteMapNodeModelMapper.MapToSiteMapNodeModel(node, mvcNode, NavSourceMetadata); 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; }
/// <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 NavHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth, bool drillDownToCurrent) { // Build model var model = new NavHelperModel(); 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, NavSourceMetadata); } // Check ACL if (node.IsAccessibleToUser(HttpContext.Current)) { // Add node? var nodeToAdd = SiteMapNodeModelMapper.MapToSiteMapNodeModel(node, mvcNode, NavSourceMetadata); 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); }