示例#1
0
文件: V1.cs 项目: yeungsta/menu-dart
        private void AddMenuList(HtmlTextWriter writer, List <MenuNode> nodeList)
        {
            writer.AddAttribute(Constants.DataRole, "listview");
            writer.AddAttribute(Constants.DataInset, "true");
            writer.RenderBeginTag(HtmlTextWriterTag.Ul);

            if (nodeList != null)
            {
                foreach (MenuNode node in nodeList)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Li);
                    writer.WriteLine();
                    writer.Indent++;

                    if (node is MenuLeaf)
                    {
                        MenuLeaf leaf = node as MenuLeaf;
                        AddMenuLeaf(writer, leaf.Title, leaf.Description, leaf.Price);
                    }
                    else
                    {
                        AddMenuNode(writer, node.Title, "#" + node.Link);
                    }

                    writer.Indent--;
                    writer.RenderEndTag();
                    writer.WriteLine();
                }
            }

            writer.RenderEndTag();
        }
示例#2
0
        private static void MenuExample()
        {
            var menu1 = new MenuContainer(new MenuComponent[]
            {
                new MenuLeaf("1. My profile"),
                new MenuComposite("2. Admin", new[]
                {
                    new MenuLeaf("2.1. Admin page")
                }),
                new MenuComposite("3. Lists", new MenuComponent[]
                {
                    new MenuLeaf("3.1. Admin page"),
                    new MenuLeaf("3.2. Lecturers"),
                    new MenuComposite("3.3 Students", new MenuComponent[]
                    {
                        new MenuComposite("3.3.1. 1-st year", new[]
                        {
                            new MenuLeaf("3.3.1.1. Computer science"),
                            new MenuLeaf("3.3.1.2. Mathematics"),
                            new MenuLeaf("3.3.1.3. Admin page")
                        }),
                        new MenuLeaf("3.3.2. 2-nd year")
                    })
                })
            });

            var menu2 = new MenuComposite("1. My second menu", new[]
            {
                new MenuLeaf("1.1. My profile"),
                new MenuLeaf("1.2. My settings"),
            });

            var menu3 = new MenuContainer(new[] { new MenuLeaf("1. My profile menu") });

            var menu4 = new MenuLeaf("1. My forth menu");

            var menus = new MenuComponent[] { menu1, menu2, menu3, menu4 };

            foreach (var menu in menus)
            {
                Console.WriteLine(menu.Render());
                Console.WriteLine();
                Console.WriteLine(@"------");
                Console.WriteLine();
            }
        }
示例#3
0
        public ActionResult EditItem(MenuLeaf newMenuLeaf, int id, string parent, int idx)
        {
            if ((id == 0) || !Utilities.IsThisMyMenu(id, db, User))
            {
                return(RedirectToAction("MenuBuilderAccessViolation", "Menu"));
            }

            //we need a parent ID in order to know where to edit
            if (!string.IsNullOrEmpty(parent))
            {
                if ((ModelState.IsValid) && (!string.IsNullOrEmpty(newMenuLeaf.Title)))
                {
                    Menu menu = db.Menus.Find(id);

                    if (menu == null)
                    {
                        Utilities.LogAppError("Could not find menu.");
                        return(HttpNotFound());
                    }

                    //deserialize current menu tree
                    List <MenuNode> currentMenuTree = V1.DeserializeMenuTree(menu.MenuTree);

                    //check if this is the root level
                    if (parent == Constants.RootLevel)
                    {
                        //update item
                        currentMenuTree[idx] = newMenuLeaf;
                    }
                    else
                    {
                        //find the parent node
                        MenuNode parentNode = V1.FindMenuNode(currentMenuTree, parent);

                        if (parentNode != null)
                        {
                            //update item
                            parentNode.Branches[idx] = newMenuLeaf;
                        }
                    }

                    //serialize back into the menu
                    menu.MenuTree = V1.SerializeMenuTree(currentMenuTree);

                    //mark menu as dirty
                    menu.ChangesUnpublished = true;

                    //save menu
                    db.Entry(menu).State = EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("Details", new { id = id, parent = parent, idx = -1 }));
                }

                //send it back to the form
                ViewBag.Parent = parent;
                ViewBag.MenuId = id;
                ViewBag.Idx    = idx;

                return(View(newMenuLeaf));
            }

            return(HttpNotFound());
        }
示例#4
0
        public ActionResult CreateItem(MenuLeaf newMenuLeaf, int id, string parent)
        {
            if ((id == 0) || !Utilities.IsThisMyMenu(id, db, User))
            {
                return(RedirectToAction("MenuBuilderAccessViolation", "Menu"));
            }

            //we need a parent in order to know where to create these menu nodes
            if (!string.IsNullOrEmpty(parent))
            {
                if ((ModelState.IsValid) && (!string.IsNullOrEmpty(newMenuLeaf.Title)))
                {
                    Menu menu = db.Menus.Find(id);

                    if (menu == null)
                    {
                        Utilities.LogAppError("Could not find menu.");
                        return(HttpNotFound());
                    }

                    //first deserialize current menu tree
                    List <MenuNode> currentMenuTree = V1.DeserializeMenuTree(menu.MenuTree);

                    if ((currentMenuTree != null) && (currentMenuTree.Count > 0))
                    {
                        //if parent is empty, this is the root level
                        if (parent == Constants.RootLevel)
                        {
                            //add node to the root level
                            currentMenuTree.Add(newMenuLeaf);
                        }
                        else
                        {
                            //find the parent node
                            MenuNode parentNode = V1.FindMenuNode(currentMenuTree, parent);

                            if (parentNode != null)
                            {
                                //add node to the parent's branches
                                parentNode.Branches.Add(newMenuLeaf);
                            }
                        }

                        //serialize back into the menu
                        menu.MenuTree = V1.SerializeMenuTree(currentMenuTree);
                    }
                    else
                    {
                        //no current nodes, so just set serialized data directly into menu
                        List <MenuNode> newMenuNodes = new List <MenuNode>();
                        newMenuNodes.Add(newMenuLeaf as MenuNode);

                        menu.MenuTree = V1.SerializeMenuTree(newMenuNodes);
                    }

                    //mark menu as dirty
                    menu.ChangesUnpublished = true;

                    //save menu to DB
                    db.Entry(menu).State = EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("Details", new { id = id, parent = parent, idx = -1 }));
                }

                //send it back to the form
                ViewBag.Parent = parent;
                ViewBag.MenuId = id;

                return(View(newMenuLeaf));
            }

            return(HttpNotFound());
        }