private async Task <Stack <Ad> > GetAdsAsync(Core.Entities.Site site) { if (_ads != null) { return(_ads); } var ads = await _adsRepository.GetAllAsync(queryable => queryable.ForSite(site).Where(ad => ad.IsPublished)); Shuffle(ads.items); _ads = new Stack <Ad>(ads.items); return(_ads); }
public async Task <IEnumerable <RssItem> > GetItemsAsync(Core.Entities.Site site, int count) { var posts = await _postsRepository.GetAllWithBlocksAsync(entities => entities.Where(e => e.IsPublished).ForSite(site).OrderByDescending(p => p.DatePublished).Take(count)); DateTimeOffset?mostRecentPubDate = DateTimeOffset.MinValue; var commentsData = await _commentsProvider.GetCommentsDataAsync(posts.items.Select(p => p as IContentItem).ToArray(), site); var items = new List <RssItem>(); foreach (var post in posts.items) { if (post.DatePublished != null) { var newsDate = post.DatePublished; if (newsDate > mostRecentPubDate) { mostRecentPubDate = newsDate; } var postUrl = _linkGenerator.GeneratePublicUrl(post, site); var item = new RssItem { Title = post.Title, Description = GetDescription(post), Link = postUrl, PublicationDate = newsDate.Value.DateTime, Author = post.Author.Name, Guid = new RssGuid(postUrl.ToString(), true) }; if (commentsData.ContainsKey(post.Id)) { item.Comments = commentsData[post.Id].uri; } foreach (var section in post.Sections) { item.Categories.Add(new RssCategory(section.Title, _linkGenerator.GeneratePublicUrl(section).ToString())); } items.Add(item); } } return(items); }
public async Task <Ad?> NextAsync(Core.Entities.Site site) { var ads = await GetAdsAsync(site); return(ads.Count > 0 ? ads.Pop() : null); }