public async Task <BlogEntryResult> GetBlogEntriesAsync(int page, string contentTypeId, CancellationToken cancellationToken) { if (page == 1) { var cachedEntries = _cacheProvider.GetCachedBlogEntries(); if (cachedEntries != null && cachedEntries.Items.Any()) { return(cachedEntries); } } var result = await _contentfulClient.SearchAsync <Entry>(cancellationToken, new [] { new EqualitySearchFilter(BuiltInProperties.ContentType, contentTypeId), }, BuiltInProperties.SysUpdatedAt, OrderByDirection.Descending, (page - 1) *10, 10); var blogEntries = GetBlogEntryResultFromSearchResult(result); if (page == 1) { _cacheProvider.SetCachedBlogEntries(blogEntries); } return(blogEntries); }
// GET: All Dogs public async Task <ActionResult> AllAsync(CancellationToken cancellationToken) { var results = await _contentfulClient.SearchAsync <Entry>(cancellationToken, new[] { // Only search for the 'Dog' content type new EqualitySearchFilter(BuiltInProperties.ContentType, "3KzwWGrzry422cEkMCA2o6"), }, includeLevels : 1 // Ensure we retrieve the linked assets inside this one request - we want to get the Images for the dogs too ); return(View(GetAllDogsFromContentfulResult(results))); }
public async Task <SearchResult <Entry> > GetArticlesByTag(string tagKey) { var searchFilters = new ISearchFilter[] { new EqualitySearchFilter(BuiltInProperties.ContentType, contentType), new EqualitySearchFilter("fields.tags", tagKey.ToLower()) }; try { var articles = await contentfulClient.SearchAsync <Entry>(cancellationToken, searchFilters); if (articles.Total == 0) { return new SearchResult <Entry> { Total = 0, Items = null } } ; return(articles); } catch (Exception Ex) { return(null); } }