/// <summary>
        /// Gets a list of `SubNav` items under the `Node` passed in.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public IEnumerable <SubNav> GetSubNavFromNode(ITreeNode node)
        {
            var subnavList = new List <SubNav>();

            try
            {
                foreach (ITreeNode Node in DocumentQueryHelper.RepeaterQuery(
                             Path: node.NodeAliasPath + "/%",
                             ClassNames: "CMS.MenuItem",
                             OrderBy: "NodeLevel, NodeOrder",
                             Columns: "MenuItemName,NodeAliasPath"
                             ))
                {
                    subnavList.Add(new SubNav()
                    {
                        LinkText = Node.GetValue("MenuItemName").ToString(),
                        // You have to decide what your URL will be, for us our URLs = NodeAliasPath
                        LinkUrl = Node.NodeAliasPath
                    });
                }
            }
            catch (Exception ex)
            {
                _eventLogService.LogException("ExampleService", "GET", ex);
            }
            return(subnavList);
        }
        /// <summary>
        /// This Repeater "Web Part" is given the ViewBag (since it's normally not available on child actions) and configures itself from this.
        /// This allows for easy calling and adjustment to this "Web Parts" Logic without really needing adjustments on the calling Views, but
        /// is very much tied into the source (ex: Kentico).  It would be hard to flip this with Kentico Cloud if you wished to use that.
        /// </summary>
        /// <param name="ViewBag">The ViewBag which will have the Document, Culture, and Site Context</param>
        /// <returns></returns>
        public ActionResult NavigationByContext(dynamic ViewBag)
        {
            // Build the actual Partial View's model from the data provided by the parent View
            ExampleMVCWebPartsSubNavs Model = new ExampleMVCWebPartsSubNavs();
            var subNavs = new List <SubNav>();

            // Get the Sub Nav Items
            foreach (ITreeNode Node in DocumentQueryHelper.RepeaterQuery(
                         Path: ViewBag.CurrentDocument.NodeAliasPath + "/%",
                         CultureCode: ((CultureInfo)ViewBag.CurrentCulture).CultureCode,
                         SiteName: ((ISiteInfo)ViewBag.CurrentSite).SiteName,
                         ClassNames: "CMS.MenuItem",
                         OrderBy: "NodeLevel, NodeOrder",
                         Columns: "MenuItemName,NodeAliasPath"
                         ))
            {
                subNavs.Add(new SubNav()
                {
                    LinkText = Node.GetValue("MenuItemName").ToString(),
                    // You have to decide what your URL will be, for us our URLs = NodeAliasPath
                    LinkUrl = Node.NodeAliasPath
                });
            }

            Model.SubNavigation = subNavs;
            return(View("Navigation", Model));
        }
        /// <summary>
        /// Example of how to do Web Parts in MVC Using RenderAction, and in this case the parent Controller is filling a model
        /// that will be passed to the "Web Part" (Action) in order to render.  More leg work but also source-agnostic. (Model-View-ViewModel MVVM)
        /// </summary>
        /// <returns></returns>
        public ActionResult MVCWebPartsViewModel()
        {
            TreeNode FoundNode = DocumentQueryHelper.GetNodeByAliasPath(HttpContext.Request.Url.AbsolutePath);

            if (FoundNode != null)
            {
                ExampleMVCWebPartsViewModel Model = new ExampleMVCWebPartsViewModel();
                // Get the Sub Nav Items
                foreach (TreeNode Node in DocumentQueryHelper.RepeaterQuery(
                             Path: FoundNode.NodeAliasPath + "/%",
                             ClassNames: "CMS.MenuItem",
                             OrderBy: "NodeLevel, NodeOrder",
                             Columns: "MenuItemName,NodeAliasPath"
                             ))
                {
                    Model.SubNavigation.Add(new SubNav()
                    {
                        LinkText = Node.GetValue("MenuItemName", ""),
                        // You have to decide what your URL will be, for us our URLs = NodeAliasPath
                        LinkUrl = Node.NodeAliasPath
                    });
                }
                return(View(Model));
            }
            else
            {
                return(HttpNotFound("Could not find page by that Url"));
            }
        }
        public ActionResult Banners()
        {
            TreeNode FoundNode = DocumentQueryHelper.GetNodeByAliasPath(HttpContext.Request.Url.AbsolutePath);

            if (FoundNode != null)
            {
                SetContext(FoundNode.DocumentID);
                // Get Banners
                ExampleBannersViewModel Model = new ExampleBannersViewModel();
                Model.BannerNameUrlsList = new List <ExampleBannersBanner>();
                foreach (TreeNode Banner in DocumentQueryHelper.RepeaterQuery(ClassNames: "Demo.Banner", RelationshipName: "Banners", RelationshipWithNodeGuid: FoundNode.NodeGUID))
                {
                    Model.BannerNameUrlsList.Add(new ExampleBannersBanner()
                    {
                        BannerName = Banner.GetValue <string>("BannerName", ""),
                        BannerUrl  = Banner.GetValue <string>("BannerImage", "")
                    });
                }
                return(View(Model));
            }
            else
            {
                return(HttpNotFound("Could not find page by that Url"));
            }
        }
        /// <summary>
        /// This Repeater "Webpart" Relies on just a path that would be provided through the View's context.  Does not rely on passing
        /// the ViewBag like the NavigationByContext, but does then require the calling View to provide the properties, and if ever more
        /// properties are needed, would need to adjust both Controller and View alike.
        /// </summary>
        /// <returns></returns>
        public ActionResult NavigationByPath(string Path, string Culture, string SiteName)
        {
            // Build the actual Partial View's model from the data provided by the parent View
            ExampleMVCWebPartsSubNavs Model   = new ExampleMVCWebPartsSubNavs();
            List <SubNav>             SubNavs = new List <SubNav>();

            // Get the Sub Nav Items
            foreach (TreeNode Node in DocumentQueryHelper.RepeaterQuery(
                         Path: Path + "/%",
                         CultureCode: Culture,
                         SiteName: SiteName,
                         ClassNames: "CMS.MenuItem",
                         OrderBy: "NodeLevel, NodeOrder",
                         Columns: "MenuItemName,NodeAliasPath"
                         ))
            {
                Model.SubNavigation.Add(new SubNav()
                {
                    LinkText = Node.GetValue("MenuItemName", ""),
                    // You have to decide what your URL will be, for us our URLs = NodeAliasPath
                    LinkUrl = Node.NodeAliasPath
                });
            }
            return(View("Navigation", Model));
        }
        // GET: Home
        public ActionResult Index()
        {
            // Get the current page, in this case we know it's the Home page
            var HomePage = DocumentQueryHelper.RepeaterQuery(Path: "/Home", ClassNames: "MVC.Home", CacheItemName: "HomePage").GetTypedResult().Items.FirstOrDefault();

            HttpContext.Kentico().PageBuilder().Initialize(HomePage.DocumentID);
            SetContext(HomePage.DocumentID);
            return(View());
        }
        /// <summary>
        /// Gets a list of `SubNav` items under the `Node` passed in.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public IEnumerable <SubNav> GetSubNavFromAliasPath(string nodeAliasPath, CultureInfo cultureInfo = null, ISiteInfo siteInfo = null)
        {
            if (siteInfo == null)
            {
                // If site is not provided, get the current site
                siteInfo = _siteService.CurrentSite;
                _eventLogService.LogEvent("GetSubNavFromAliasPath", "ExampleService", "GET", "Using current site");
            }
            else
            {
                _eventLogService.LogEvent("GetSubNavFromAliasPath", "ExampleService", "GET", "Using passed in site");
            }

            if (cultureInfo == null)
            {
                cultureInfo = LocalizationContext.GetCurrentCulture();
                _eventLogService.LogEvent("GetSubNavFromAliasPath", "ExampleService", "GET", "Using current culture");
            }
            else
            {
                _eventLogService.LogEvent("GetSubNavFromAliasPath", "ExampleService", "GET", "Using passed in culture");
            }

            var subnavList = new List <SubNav>();

            try
            {
                foreach (ITreeNode Node in DocumentQueryHelper.RepeaterQuery(
                             Path: nodeAliasPath + "/%",
                             CultureCode: cultureInfo.CultureCode,
                             SiteName: siteInfo.SiteName,
                             ClassNames: "CMS.MenuItem",
                             OrderBy: "NodeLevel, NodeOrder",
                             Columns: "MenuItemName,NodeAliasPath"
                             ))
                {
                    subnavList.Add(new SubNav()
                    {
                        LinkText = Node.GetValue("MenuItemName").ToString(),
                        // You have to decide what your URL will be, for us our URLs = NodeAliasPath
                        LinkUrl = Node.NodeAliasPath
                    });
                }
            }
            catch (Exception ex)
            {
                _eventLogService.LogException("ExampleService", "GET", ex);
            }
            return(subnavList);
        }
        /// <summary>
        /// Gets a list of `Demo.Banner` items under the `Node` passed in.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public IEnumerable <ExampleBannersBanner> GetBannersFromNode(ITreeNode node)
        {
            var bannerList = new List <ExampleBannersBanner>();

            try
            {
                foreach (ITreeNode Banner in DocumentQueryHelper.RepeaterQuery(ClassNames: "Demo.Banner", RelationshipName: "Banners", RelationshipWithNodeGuid: node.NodeGUID))
                {
                    bannerList.Add(new ExampleBannersBanner()
                    {
                        BannerName = Banner.GetValue("BannerName").ToString(),
                        BannerUrl  = Banner.GetValue("BannerImage").ToString()
                    });
                }
            }
            catch (Exception ex)
            {
                _eventLogService.LogException("ExampleService", "GET", ex);
            }
            return(bannerList);
        }