public static List <PagePortfolioItem> GetPrevNext(this PagePortfolioItem item) { SectionPortfolio portfolioRoot = item.Ancestor <SectionPortfolio>(); PortfolioHelper h = new PortfolioHelper(portfolioRoot); //Get a portfoliohelper to get items in the same order as defined in portfolio settings IEnumerable <DGenericCategoryItem> categories = item.GetPickerItemsByValue <DGenericCategoryItem>(item.Categories); //Get the next / previous item related to the current item IEnumerable <PagePortfolioItem> allItems = h.GetPortfolioItems(); //See if we must restrict to current item's categories if (portfolioRoot.NextPrevRestrictToCategories) { allItems = allItems.Where(x => x.Categories.IsContainedInCsv(item.Categories)); } List <PagePortfolioItem> sandwitchedItems = allItems.FindSandwichedItem(x => x.Id == item.Id).ToList <PagePortfolioItem>(); //Remove current page fron list sandwitchedItems.RemoveAt(1); return(sandwitchedItems); }
public static bool MustShowRelated(this PagePortfolioItem item) { SectionPortfolio portfolioRoot = item.Ancestor <SectionPortfolio>(); PortfolioHelper h = new PortfolioHelper(portfolioRoot); if (string.IsNullOrEmpty(item.RelatedItems) && !portfolioRoot.RandomRelated) { return(false); } return(true); }
public static IEnumerable <PagePortfolioItem> GetRelatedItems(this PagePortfolioItem item) { SectionPortfolio portfolioRoot = item.Ancestor <SectionPortfolio>(); PortfolioHelper h = new PortfolioHelper(portfolioRoot); if (string.IsNullOrEmpty(item.RelatedItems) && portfolioRoot.RandomRelated) { IEnumerable <PagePortfolioItem> randomItems = h.GetPortfolioItemsRandom(); if (portfolioRoot.RandomRelatedRestrictToCategories) { return(randomItems.Where(x => x.Categories.IsContainedInCsv(item.Categories)).Take(h.GlobalRandomRelatedNumber)); } else { return(randomItems.Take(h.GlobalRandomRelatedNumber)); } } else { return(item.GetPickerItemsByValue <PagePortfolioItem>(item.RelatedItems)); } }