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 string GetPortfolioCategoryNames(this PagePortfolioItem item) { StringBuilder sb = new StringBuilder(string.Empty); foreach (IPublishedContent category in item.GetPickerItemsByValue(item.Categories)) { sb.Append(category.Name); sb.Append(", "); } string categoryNames = (sb.Length > 0) ? sb.ToString().Substring(0, (sb.ToString().Length - 2)) : ""; return(categoryNames); }
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)); } }