Carrotware.CMS.Core.SiteNavHelperReal.GetLevelDepthNavigation C# (CSharp) Method

GetLevelDepthNavigation() public method

public GetLevelDepthNavigation ( System.Guid siteID, int iDepth, bool bActiveOnly ) : List
siteID System.Guid
iDepth int
bActiveOnly bool
return List
        public List<SiteNav> GetLevelDepthNavigation(Guid siteID, int iDepth, bool bActiveOnly)
        {
            List<SiteNav> lstContent = null;
            List<Guid> lstSub = new List<Guid>();

            if (iDepth < 1) {
                iDepth = 1;
            }

            if (iDepth > 10) {
                iDepth = 10;
            }

            List<Guid> lstTop = CompiledQueries.TopLevelPages(db, siteID, false).Select(z => z.Root_ContentID).ToList();

            while (iDepth > 1) {
                lstSub = (from ct in CannedQueries.GetLatestContentList(db, siteID, bActiveOnly)
                          where ct.SiteID == siteID
                                && ct.ShowInSiteNav == true
                                && (ct.PageActive == true || bActiveOnly == false)
                                && ct.IsLatestVersion == true
                                && (ct.GoLiveDate < DateTime.UtcNow || bActiveOnly == false)
                                && (ct.RetireDate > DateTime.UtcNow || bActiveOnly == false)
                                && (!lstTop.Contains(ct.Root_ContentID) && lstTop.Contains(ct.Parent_ContentID.Value))
                          select ct.Root_ContentID).Distinct().ToList();

                lstTop = lstTop.Union(lstSub).ToList();

                iDepth--;
            }

            lstContent = (from ct in CannedQueries.GetLatestContentList(db, siteID, bActiveOnly)
                          orderby ct.NavOrder, ct.NavMenuText
                          where ct.SiteID == siteID
                                && ct.ShowInSiteNav == true
                                && (ct.PageActive == true || bActiveOnly == false)
                                && ct.IsLatestVersion == true
                                && (ct.GoLiveDate < DateTime.UtcNow || bActiveOnly == false)
                                && (ct.RetireDate > DateTime.UtcNow || bActiveOnly == false)
                                && lstTop.Contains(ct.Root_ContentID)
                          select new SiteNav(ct)).ToList();

            return lstContent;
        }