private Expression <Func <Entries, bool> > GetBlogFilter(GetBlogEntriesParameter param) { Expression <Func <Entries, bool> > filter; if (!string.IsNullOrEmpty(param.Tags)) { var tagsList = param.Tags.Split(',').Select(i => BlogFacade.Decode(i)).ToList(); filter = f => Enumerable.Intersect(f.Tags.Split(','), tagsList).Count() == tagsList.Count && (param.BlogPageId == Guid.Empty || f.PageId == param.BlogPageId); } else { filter = f => param.BlogPageId == Guid.Empty || f.PageId == param.BlogPageId; } return(filter); }
public BlogListModel GetBlogEntries([FromUri] GetBlogEntriesParameter param) { var culture = DataLocalizationFacade.DefaultLocalizationCulture; if (!string.IsNullOrEmpty(param.CultureCode)) { culture = CultureInfo.GetCultureInfo(param.CultureCode); } using (var con = new DataConnection(PublicationScope.Published, culture)) { var model = new BlogListModel(); var filter = GetBlogFilter(param); var entries = con.Get <Entries>().Where(filter).OrderByDescending(e => e.Date).ToList(); var entriesCount = entries.Count(); model.Title = GetBlogListTitle(param.Tags, entriesCount); model.PageCount = param.PageSize == 0 ? entriesCount : (entriesCount + param.PageSize - 1) / param.PageSize; model.PageNumber = param.PageNumber; var entriesForPage = param.PageSize == 0 ? entries : entries.Skip(param.PageSize * (param.PageNumber - 1)).Take(param.PageSize).ToList(); model.Items = new List <BlogListItemModel>(); var pageUrl = GetFullBlogPageUrl(param.BlogPageId); foreach (var entry in entriesForPage) { model.Items.Add(CreateBlogItemModel(entry, pageUrl)); } return(model); } }
private Expression<Func<Entries, bool>> GetBlogFilter(GetBlogEntriesParameter param) { Expression<Func<Entries, bool>> filter; if (!string.IsNullOrEmpty(param.Tags)) { var tagsList = param.Tags.Split(',').Select(i => BlogFacade.Decode(i)).ToList(); filter = f => Enumerable.Intersect(f.Tags.Split(','), tagsList).Count() == tagsList.Count && (param.BlogPageId == Guid.Empty || f.PageId == param.BlogPageId); } else { filter = f => param.BlogPageId == Guid.Empty || f.PageId == param.BlogPageId; } return filter; }