Esempio n. 1
0
        public IList <MenuPortalListApiModel> GetMenuList()
        {
            var menus = _sysRoleRespository.GetMenuList();
            var ps    = menus.Select(x => new RoleMenuApiModel {
                IsCheck = false, Menu = x
            }).ToList();
            var result  = new List <MenuPortalListApiModel>();
            var portals = menus.Select(x => x.Portal.Id).Distinct();

            foreach (var portal in portals)
            {
                var tops1 = menus.Where(x => x.ParentId == 0 && x.Portal.Id == portal).ToList();
                if (tops1.Any())
                {
                    var p  = tops1.First().Portal;
                    var ts = tops1.Select(x => new RoleMenuApiModel {
                        IsCheck = false, Menu = x
                    }).ToList();

                    foreach (var menu in ts)
                    {
                        menu.FindChildren(ps);
                    }
                    result.Add(new MenuPortalListApiModel {
                        Portal = p, Menus = ts
                    });
                }
            }
            return(result);
        }