public async Task <IActionResult> Edit(int id, [Bind("Id,ControllerName,ActionName")] MenuHelperModel menuHelperModel)
        {
            if (id != menuHelperModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(menuHelperModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MenuHelperModelExists(menuHelperModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(menuHelperModel));
        }
        public async Task <IActionResult> Create([Bind("Id,ControllerName,ActionName")] MenuHelperModel menuHelperModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(menuHelperModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(menuHelperModel));
        }
Exemplo n.º 3
0
        internal static MenuHelperModel BuildModel(IMenuNode node)
        {
            var model = new MenuHelperModel();

            if (node == null)
            {
                return(model);
            }

            if (node.IsAccessibleToUser())
            {
                var nodeToAdd = new SiteMapNodeModel(node);
                model.Nodes.AddRange(nodeToAdd.Children);
            }
            return(model);
        }
Exemplo n.º 4
0
        /// <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>
        /// <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, SourceMetadataDictionary sourceMetadata, ISiteMapNode startingNode, bool startingNodeInChildLevel, bool showStartingNode, int maxDepth, bool drillDownToCurrent)
        {
            // Build model
            var model = new MenuHelperModel();
            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, maxDepth, drillDownToCurrent, startingNodeInChildLevel);
                // Check visibility
                if (node.IsVisible(sourceMetadata))
                {
                    if (showStartingNode || !startingNodeInChildLevel)
                    {
                        model.Nodes.Add(nodeToAdd);
                    }
                    // Add child nodes
                    if (startingNodeInChildLevel)
                    {
                        model.Nodes.AddRange(nodeToAdd.Children);
                    }
                }
            }

            return model;
        }
Exemplo n.º 5
0
        /// <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)
        {
            // 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;
        }
Exemplo n.º 6
0
        public static MvcHtmlString Menu(this MvcSiteMapHtmlHelper helper)
        {
            MenuHelperModel model = BuildModel(MVCSiteMap.StartingNode);

            //MenuNode node = new MenuNode();
            //node.Title = "tesst1";
            //node.Url = "dsdsd";
            //node.IsClickable = false;
            //SiteMapNodeModel nodemodel = new SiteMapNodeModel(node);


            //MenuNode node2 = new MenuNode();
            //node.Title = "tesst22221";
            //node.Url = "dsdsd2222";
            //node.IsClickable = false;
            //SiteMapNodeModel nodemodel2 = new SiteMapNodeModel(node);


            //MenuNode node3 = new MenuNode();
            //node.Title = "tesst333";
            //node.Url = "dsdsd33";
            //node.IsClickable = true;
            //SiteMapNodeModel nodemodel3 = new SiteMapNodeModel(node);


            //MenuNode node4 = new MenuNode();
            //node.Title = "tesst331";
            //node.Url = "dsdsd333";
            //node.IsClickable = true;
            //SiteMapNodeModel nodemodel4 = new SiteMapNodeModel(node);


            //MenuNode node5 = new MenuNode();
            //node.Title = "tesst335553";
            //node.Url = "dsdsd35553";
            //node.IsClickable = true;
            //SiteMapNodeModel nodemodel5 = new SiteMapNodeModel(node);


            //MenuNode node6 = new MenuNode();
            //node.Title = "tesst366631";
            //node.Url = "dsdsd336663";
            //node.IsClickable = true;
            //SiteMapNodeModel nodemodel6 = new SiteMapNodeModel(node);

            //nodemodel3.Children.Add(nodemodel6);
            //nodemodel3.Children.Add(nodemodel5);

            //nodemodel2.Children.Add(nodemodel3);
            //nodemodel2.Children.Add(nodemodel4);


            //MenuHelperModel menu = new MenuHelperModel();
            //menu.Nodes.Add(nodemodel);
            //menu.Nodes.Add(nodemodel2);


            return(helper
                   .CreateHtmlHelperForModel(model)
                   .DisplayFor(m => model, null));
        }
Exemplo n.º 7
0
        /// <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);
        }