Пример #1
0
        public override void Load()
        {
            List <ENTMenuItem> menuItems = new ENTMenuItemData().Select();

            foreach (var item in menuItems)
            {
                var menuItemBO = new ENTMenuItemBO();
                menuItemBO.MapEntityToProperties(item);
                if (MenuExist(menuItemBO.ID) == false)
                {
                    if (menuItemBO.ParentMenuItemId == null)
                    {
                        this.Add(menuItemBO);
                    }
                    else
                    {
                        var parent = GetByMenuItemId(Convert.ToInt32(menuItemBO.ParentMenuItemId));
                        if (parent == null)
                        {
                            // If it gets here then the parent isn’t in the list yet.
                            // Find the parent in the list.
                            ENTMenuItemBO newParentMenuItem = FindOrLoadParent(menuItems, Convert.ToInt32(menuItemBO.ParentMenuItemId));
                            // Add the current child menu item to the newly added parent
                            newParentMenuItem.ChildMenuList.Add(menuItemBO);
                        }
                        else
                        {
                            parent.ChildMenuList.Add(menuItemBO);
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// This will load up the object with the correct parent\child relationships within the menu structure.
        /// Any parent menu item will have its child menu items loaded in it's ChildMenuItems property.
        /// </summary>
        public override void Load()
        {
            //Load the list from the database.  This will then be traversed to create the
            //parent child relationships in for each menu item.
            List <ENTMenuItem> menuItems = new ENTMenuItemData().Select();

            //Traverse through the list to create the parent child relationships
            foreach (ENTMenuItem menuItem in menuItems)
            {
                var menuItemBO = new ENTMenuItemBO();
                menuItemBO.MapEntityToProperties(menuItem);

                // Check if the menu already exists in this object.
                if (MenuExists(menuItemBO.ID) == false)
                {
                    //Doesn't exist so now check if this is a top level item.
                    if (menuItemBO.ParentMenuItemId == null)
                    {
                        //Top level item so just add it.
                        this.Add(menuItemBO);
                    }
                    else
                    {
                        // Get the parent menu item from this object if it exists.
                        ENTMenuItemBO parent = GetByMenuItemId(Convert.ToInt32(menuItemBO.ParentMenuItemId));

                        if (parent == null)
                        {
                            // If it gets here then the parent isn't in the list yet.
                            // Find the parent in the list.
                            ENTMenuItemBO newParentMenuItem = FindOrLoadParent(menuItems, Convert.ToInt32(menuItemBO.ParentMenuItemId));

                            // Add the current child menu item to the newly added parent
                            newParentMenuItem.ChildMenuItems.Add(menuItemBO);
                        }
                        else
                        {
                            // Parent already existed in this object.
                            // Add this menu to the child of the parent
                            parent.ChildMenuItems.Add(menuItemBO);
                        }
                    }
                }
            }
        }