Ejemplo n.º 1
0
 public MenuCreateHandler(GlobalSolusindoDb db, tblM_User user, MenuValidator menuValidator, MenuFactory menuFactory, MenuQuery menuQuery, AccessControl accessControl) : base(db, user)
 {
     this.menuValidator         = menuValidator;
     this.menuFactory           = menuFactory;
     this.menuQuery             = menuQuery;
     this.menuEntryDataProvider = new MenuEntryDataProvider(db, user, accessControl, menuQuery);
 }
Ejemplo n.º 2
0
        public TreeMenu GenerateMenus(int userPk)
        {
            var menuQuery      = new MenuQuery();
            var roles          = GetRoles(userPk);
            var roleMenus      = roles.Where(x => x.Title.Contains("ViewAll"));
            var showAllMenu    = roles.Where(x => x.Title.Contains("Menu_ViewAll")).Count() > 0;
            var menus          = new List <MenuDTO>();
            var groupMenus     = new List <GroupMenu>();
            var groupMenuNames = new List <string>();
            var treeMenu       = new TreeMenu();

            if (showAllMenu)
            {
                var allMenus = menuQuery.GetQuery().ToList();

                groupMenuNames = allMenus
                                 .GroupBy(x => x.ParentGroup)
                                 .Select(g => g.FirstOrDefault())
                                 .Select(x => x.ParentGroup)
                                 .ToList();


                foreach (var groupName in groupMenuNames)
                {
                    var newGroupMenu = new GroupMenu();
                    newGroupMenu.GroupName = groupName;
                    newGroupMenu.Menus     = allMenus
                                             .Where(x => x.ParentGroup == groupName)
                                             .Select(x => new MenuNode
                    {
                        Caption = x.Caption,
                        Code    = x.Code,
                        Path    = x.Path
                    })
                                             .ToList();

                    groupMenus.Add(newGroupMenu);
                }

                treeMenu.GroupMenus = groupMenus;

                return(treeMenu);
            }


            foreach (var role in roleMenus)
            {
                var menuCode = role.Title;
                var menu     = menuQuery.GetByCode(menuCode);
                if (menu != null)
                {
                    menus.Add(menu);
                }
            }

            groupMenuNames = menus
                             .GroupBy(x => x.ParentGroup)
                             .Select(g => g.FirstOrDefault())
                             .Select(x => x.ParentGroup)
                             .ToList();

            foreach (var groupName in groupMenuNames)
            {
                var newGroupMenu = new GroupMenu();
                newGroupMenu.GroupName = groupName;
                newGroupMenu.Menus     = menus
                                         .Where(x => x.ParentGroup == groupName)
                                         .Select(x => new MenuNode
                {
                    Caption = x.Caption,
                    Code    = x.Code,
                    Path    = x.Path
                })
                                         .ToList();

                groupMenus.Add(newGroupMenu);
            }

            treeMenu.GroupMenus = groupMenus;

            return(treeMenu);
        }