Esempio n. 1
0
        public ActionResult Index(NavigationManagementViewModel model, int?menuId)
        {
            var menus = Services.ContentManager.Query("Menu").List().ToList()
                        .OrderBy(x => x.ContentManager.GetItemMetadata(x).DisplayText);

            if (!menus.Any())
            {
                if (!Services.Authorizer.Authorize(Permissions.ManageMenus, T("Not allowed to manage menus")))
                {
                    return(new HttpUnauthorizedResult());
                }

                return(RedirectToAction("Create", "Admin", new { area = "Contents", id = "Menu", returnUrl = Request.RawUrl }));
            }

            var allowedMenus = menus.Where(menu => Services.Authorizer.Authorize(Permissions.ManageMenus, menu)).ToList();

            if (!allowedMenus.Any())
            {
                return(new HttpUnauthorizedResult());
            }

            IContent currentMenu = menuId == null
                ? allowedMenus.FirstOrDefault()
                : allowedMenus.FirstOrDefault(menu => menu.Id == menuId);

            if (currentMenu == null && menuId != null)   // incorrect menu id passed
            {
                return(RedirectToAction("Index"));
            }

            if (model == null)
            {
                model = new NavigationManagementViewModel();
            }

            if (model.MenuItemEntries == null || !model.MenuItemEntries.Any())
            {
                model.MenuItemEntries = _menuService.GetMenuParts(currentMenu.Id).Select(CreateMenuItemEntries).OrderBy(menuPartEntry => menuPartEntry.Position, new FlatPositionComparer()).ToList();
            }

            model.MenuItemDescriptors = _menuManager.GetMenuItemTypes();
            model.Menus       = allowedMenus;
            model.CurrentMenu = currentMenu;

            // need action name as this action is referenced from another action
            return(View(model));
        }
Esempio n. 2
0
        public ActionResult Index(NavigationManagementViewModel model, int?menuId)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageMainMenu, T("Not allowed to manage the main menu")))
            {
                return(new HttpUnauthorizedResult());
            }

            IEnumerable <TitlePart> menus = Services.ContentManager.Query <TitlePart, TitlePartRecord>().OrderBy(x => x.Title).ForType("Menu").List();

            if (!menus.Any())
            {
                return(RedirectToAction("Create", "Admin", new { area = "Contents", id = "Menu", returnUrl = Request.RawUrl }));
            }

            IContent currentMenu = menuId == null
                ? menus.FirstOrDefault()
                : menus.FirstOrDefault(menu => menu.Id == menuId);

            if (currentMenu == null && menuId != null)   // incorrect menu id passed
            {
                Services.Notifier.Error(T("Menu not found: {0}", menuId));
                return(RedirectToAction("Index"));
            }

            if (model == null)
            {
                model = new NavigationManagementViewModel();
            }

            if (model.MenuItemEntries == null || !model.MenuItemEntries.Any())
            {
                model.MenuItemEntries = _menuService.GetMenuParts(currentMenu.Id).Select(CreateMenuItemEntries).OrderBy(menuPartEntry => menuPartEntry.Position, new FlatPositionComparer()).ToList();
            }

            model.MenuItemDescriptors = _menuManager.GetMenuItemTypes();
            model.Menus       = menus;
            model.CurrentMenu = currentMenu;

            // need action name as this action is referenced from another action
            return(View(model));
        }