Пример #1
0
        public static List <MenuModel> GetMenus(ViewControllerBase controller, ICoreService CoreService)
        {
            List <Menu> _AllMenu = null;

            var preparedMenus = new List <MenuModel>();

            if (controller.TempData["UserMenus"] != null)
            {
                _AllMenu = (List <Menu>)controller.TempData["UserMenus"];
            }
            else
            {
                //_AllMenu = CoreService.GetMenuByLogin(controller.User.Identity.Name).ToList();
                _AllMenu = CoreService.GetAllMenus().ToList();
                controller.TempData["UserMenus"] = _AllMenu;
            }

            List <Menu> parentMenus = _AllMenu.Where(c => c.ParentId == null).Distinct().ToList();

            foreach (var menu in parentMenus)
            {
                var rootMenu = new MenuModel()
                {
                    Name        = menu.Name,
                    Code        = menu.Code,
                    Alias       = menu.Alias,
                    Action      = menu.Action,
                    Controller  = menu.Controller,
                    Description = menu.Description,
                    Image       = menu.Image,
                    ImageUrl    = menu.ImageUrl,
                    Position    = 1,
                    Parent      = menu.ParentId,
                    MenuLevel   = 1,
                    Children    = new List <MenuModel>()
                };

                rootMenu.Children = PrepareMenu(_AllMenu, menu, rootMenu.MenuLevel);

                preparedMenus.Add(rootMenu);
            }

            return(preparedMenus);
        }
Пример #2
0
 public List <MenuModel> GetMenus(ViewControllerBase controller)
 {
     return(MenuHelper.GetMenus(controller, _CoreService));
 }