/// <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> public static SiteMapHelperModel BuildModel(this 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); if (!startingNodeInChildLevel) { 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> /// <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="sourceMetadata">User-defined meta data.</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, SourceMetadataDictionary sourceMetadata, ISiteMapNode startingNode, bool startingNodeInChildLevel) { // Build model var model = new SiteMapHelperModel(); var node = startingNode; // Check visibility and ACL if (node != null && node.IsVisible(sourceMetadata) && node.IsAccessibleToUser()) { // Add node var nodeToAdd = new SiteMapNodeModel(node, sourceMetadata); model.Nodes.Add(nodeToAdd); // Add child nodes if (startingNodeInChildLevel) { model.Nodes.AddRange(nodeToAdd.Descendants); } } return(model); }
/// <summary> /// Builds the model. /// </summary> /// <param name="helper">The helper.</param> /// <param name="sourceMetadata">User-defined meta data.</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> internal static SiteMapHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SourceMetadataDictionary sourceMetadata, ISiteMapNode startingNode, bool startingNodeInChildLevel, bool visibilityAffectsDescendants) { // Build model var model = new SiteMapHelperModel(); var node = startingNode; // Check if a starting node has been given if (node == null) { return(model); } // Check ACL if (node.IsAccessibleToUser()) { // Add node? var nodeToAdd = new SiteMapNodeModel(node, sourceMetadata, Int32.MaxValue, false, startingNodeInChildLevel, visibilityAffectsDescendants); // Check visibility if (node.IsVisible(sourceMetadata)) { model.Nodes.Add(nodeToAdd); // Add child nodes if (visibilityAffectsDescendants && startingNodeInChildLevel) { model.Nodes.AddRange(nodeToAdd.Children); } } // Add child nodes if (!visibilityAffectsDescendants && startingNodeInChildLevel) { model.Nodes.AddRange(nodeToAdd.Children); } } return(model); }
/// <summary> /// Builds the model. /// </summary> /// <param name="helper">The helper.</param> /// <param name="sourceMetadata">User-defined meta data.</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, SourceMetadataDictionary sourceMetadata, ISiteMapNode startingNode, bool startingNodeInChildLevel) { // Build model var model = new SiteMapHelperModel(); var node = startingNode; // Check visibility and ACL if (node != null && node.IsVisible(sourceMetadata) && node.IsAccessibleToUser()) { // Add node var nodeToAdd = new SiteMapNodeModel(node, sourceMetadata); model.Nodes.Add(nodeToAdd); // Add child nodes if (startingNodeInChildLevel) { model.Nodes.AddRange(nodeToAdd.Descendants); } } return model; }
/// <summary> /// Builds the model. /// </summary> /// <param name="helper">The helper.</param> /// <param name="sourceMetadata">User-defined meta data.</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> internal static SiteMapHelperModel BuildModel(MvcSiteMapHtmlHelper helper, SourceMetadataDictionary sourceMetadata, ISiteMapNode startingNode, bool startingNodeInChildLevel, bool visibilityAffectsDescendants) { // Build model var model = new SiteMapHelperModel(); var node = startingNode; // Check if a starting node has been given if (node == null) { return model; } // Check ACL if (node.IsAccessibleToUser()) { // Add node? var nodeToAdd = new SiteMapNodeModel(node, sourceMetadata, Int32.MaxValue, false, startingNodeInChildLevel, visibilityAffectsDescendants); // Check visibility if (node.IsVisible(sourceMetadata)) { model.Nodes.Add(nodeToAdd); // Add child nodes if (visibilityAffectsDescendants && startingNodeInChildLevel) { model.Nodes.AddRange(nodeToAdd.Children); } } // Add child nodes if (!visibilityAffectsDescendants && startingNodeInChildLevel) { model.Nodes.AddRange(nodeToAdd.Children); } } return model; }