Esempio n. 1
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var menuItems = await _queryExecutor.ExecuteAsync(new GetPermittedAdminModulesQuery());

            var vm = new AdminMenuViewModel();

            vm.ManageSiteModules = menuItems
                                   .Where(m => m.MenuCategory == AdminModuleMenuCategory.ManageSite)
                                   .SetStandardOrdering()
                                   .ToList();

            vm.SettingsModules = menuItems
                                 .Where(m => m.MenuCategory == AdminModuleMenuCategory.Settings)
                                 .SetStandardOrdering()
                                 .ToList();

            var selectedItem = menuItems
                               .Select(m => new {
                Module = m,
                Link   = m.GetMenuLinkByPath(Request.Path)
            })
                               .Where(m => m.Link != null)
                               .FirstOrDefault();

            if (selectedItem != null)
            {
                vm.SelectedCategory = selectedItem.Module.MenuCategory;
                vm.SelectedModule   = selectedItem.Module;
            }

            var viewPath = ViewPathFormatter.View("Shared", "Components/AdminMenu");

            return(View(viewPath, vm));
        }
Esempio n. 2
0
        public PartialViewResult MainMenu()
        {
            var menuItems = _queryExecutor.Execute(new GetPermittedAdminModulesQuery());
            var vm        = new AdminMenuViewModel();

            vm.ManageSiteModules = menuItems
                                   .Where(m => m.MenuCategory == AdminModuleMenuCategory.ManageSite)
                                   .SetStandardOrdering();

            vm.SettingsModules = menuItems
                                 .Where(m => m.MenuCategory == AdminModuleMenuCategory.Settings)
                                 .SetStandardOrdering();

            var selectedItem = menuItems
                               .Select(m => new {
                Module = m,
                Link   = m.GetMenuLinkByPath(Request.Url.LocalPath)
            })
                               .Where(m => m.Link != null)
                               .FirstOrDefault();

            if (selectedItem != null)
            {
                vm.SelectedCategory = selectedItem.Module.MenuCategory;
                vm.SelectedModule   = selectedItem.Module;
            }

            var viewPath = ViewPathFormatter.View("AdminMenu", "Partials/" + nameof(MainMenu));

            return(PartialView(vm));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var menuItems = await _queryExecutor.ExecuteAsync(new GetPermittedAdminModulesQuery());

            var menuCategories = _adminModuleMenuCaterories
                                 .OrderBy(c => c.Order)
                                 .ToList();

            var vm         = new AdminMenuViewModel();
            var categories = new List <AdminMenuCategoryViewModel>();

            foreach (var menuCategory in menuCategories)
            {
                var cvm = new AdminMenuCategoryViewModel();
                cvm.Category = menuCategory;

                cvm.Modules = menuItems
                              .Where(m => m.MenuCategoryType == menuCategory.GetType())
                              .SetStandardOrdering()
                              .ToList();

                // only add the category if there are items to display
                if (cvm.Modules.Count() > 0)
                {
                    categories.Add(cvm);
                }
            }

            vm.Categories = categories;

            var selectedItem = menuItems
                               .Select(m => new {
                Module       = m,
                Link         = m.GetMenuLinkByPath(Request.Path),
                CategoryType = m.MenuCategoryType
            })
                               .Where(m => m.Link != null)
                               .FirstOrDefault();

            var categoryType = selectedItem.CategoryType;

            if (selectedItem != null)
            {
                vm.SelectedCategory = menuCategories.Where(c => c.GetType() == categoryType).FirstOrDefault();
                vm.SelectedModule   = selectedItem.Module;
            }

            var viewPath = ViewPathFormatter.View("Shared", "Components/AdminMenu");

            return(View(viewPath, vm));
        }