Ejemplo n.º 1
0
        /// <inheritdoc />
        /// <summary>
        /// Gets the menu view model.
        /// </summary>
        /// <returns></returns>
        public MenuViewModel GetMenuViewModel()
        {
            string menu = "Default";

            if (userService.IsUserLoggedIn())
            {
                //// use the name of the role to be the lookup of the menu in umbraco
                //// CustomerAdmin is the one we have started with.

                menu = userService.GetDefaultRole();

                if (menu == string.Empty)
                {
                    menu = "DefaultLoggedIn";
                }
            }

            IPublishedContent menuNode = settingsService.GetMenu(menu);

            if (menuNode != null)
            {
                IEnumerable <MenuItemModel> menuItems = mainNavigationProvider.GetMenu(menuNode);

                List <MenuItemModel> allowedMenuItems = new List <MenuItemModel>();

                foreach (MenuItemModel menuItemModel in menuItems)
                {
                    if (string.IsNullOrEmpty(menuItemModel.DisplayRule) == false)
                    {
                        bool result = rulesEngineService.Execute(menuItemModel.DisplayRule);

                        if (result)
                        {
                            allowedMenuItems.Add(menuItemModel);
                        }
                    }

                    else
                    {
                        allowedMenuItems.Add(menuItemModel);
                    }
                }

                MenuViewModel viewModel = new MenuViewModel
                {
                    MenuItems = allowedMenuItems
                };

                return(viewModel);
            }

            return(new MenuViewModel());
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        /// <summary>
        /// Gets the cards.
        /// </summary>
        /// <returns></returns>
        public CardStackViewModel GetCardStack(string cardStackName)
        {
            IPublishedContent cardStackNode = settingsService.GetCardStack(cardStackName);

            if (cardStackNode != null)
            {
                IEnumerable <CardModel> cardModels = cardProvider.GetCards(cardStackNode);

                List <CardModel> allowedCards = new List <CardModel>();

                foreach (CardModel cardModel in cardModels)
                {
                    if (string.IsNullOrEmpty(cardModel.DisplayRule) == false)
                    {
                        bool result = rulesEngineService.Execute(cardModel.DisplayRule);

                        if (result)
                        {
                            allowedCards.Add(cardModel);
                        }
                    }

                    else
                    {
                        allowedCards.Add(cardModel);
                    }
                }

                CardStackViewModel viewModel = new CardStackViewModel
                {
                    Cards = allowedCards
                };

                return(viewModel);
            }

            return(new CardStackViewModel());
        }