Esempio n. 1
0
        public ActionResult Create(NavigationManagementViewModel model)
        {
            if (!_services.Authorizer.Authorize(Permissions.ManageMainMenu, T("Couldn't manage the main menu")))
            {
                return(new HttpUnauthorizedResult());
            }

            var menuPart = _services.ContentManager.New <MenuPart>("MenuItem");

            menuPart.OnMainMenu   = true;
            menuPart.MenuText     = model.NewMenuItem.Text;
            menuPart.MenuPosition = model.NewMenuItem.Position;
            if (string.IsNullOrEmpty(menuPart.MenuPosition))
            {
                menuPart.MenuPosition = Position.GetNext(_navigationManager.BuildMenu("main"));
            }

            var menuItem = menuPart.As <MenuItemPart>();

            menuItem.Url = model.NewMenuItem.Url;

            if (!ModelState.IsValid)
            {
                _services.TransactionManager.Cancel();
                return(View("Index", model));
            }

            _services.ContentManager.Create(menuPart);

            return(RedirectToAction("Index"));
        }
Esempio n. 2
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. 3
0
        public ActionResult Index(NavigationManagementViewModel model)
        {
            if (!_services.Authorizer.Authorize(Permissions.ManageMainMenu, T("Not allowed to manage the main menu")))
            {
                return(new HttpUnauthorizedResult());
            }

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

            if (model.MenuItemEntries == null || model.MenuItemEntries.Count() < 1)
            {
                model.MenuItemEntries = _menuService.Get().Select(CreateMenuItemEntries).OrderBy(menuPartEntry => menuPartEntry.Position, new FlatPositionComparer()).ToList();
            }

            // need action name as this action is referenced from another action
            return(View("Index", model));
        }
Esempio n. 4
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));
        }