Exemplo n.º 1
0
 /// <summary>
 /// Saved input <see cref="FeedItem"/> in the <see cref="FeedDocument"/> with name <paramref name="feedName"/>
 /// </summary>
 /// <param name="feedName">Name of the feed</param>
 /// <param name="feedItem"><see cref="FeedItem"/> to be saved</param>
 public async void SaveFeedItem(string feedName, FeedItem feedItem)
 {
     var result = _context.Feeds.Find(x => x.Name.Equals(feedName)).ToList().FirstOrDefault();
     if(result != null)
     {
         result.FeedItems.Add(feedItem);
         await _context.Feeds.ReplaceOneAsync<FeedDocument>(x => x.Name == result.Name, result);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Returns list of <see cref="FeedItem"/> which are not present in the database
        /// </summary>
        /// <param name="feedName">Name of the <see cref="Feed"/></param>
        /// <param name="index">Pagination index</param>
        /// <returns>Collection of <see cref="FeedItem"/></returns>
        public IEnumerable<FeedItem> GetFeedItems(string feedName)
        {
            List<FeedItem> feedItems = new List<FeedItem>();
            var result = _context.Feeds.Find(x => x.Name.Equals(feedName)).ToList().FirstOrDefault();
            if(result != null)
            {
                var latestArticles = Parser.parseFeed(result.FeedUrl);
                foreach(var article in latestArticles)
                {
                    var feedItem = new FeedItem(article);
                    feedItems.Add(feedItem);

                    if (!result.FeedItems.Any(x => x.Uid.Equals(article.Uid)))
                    {   
                        result.FeedItems.Add(feedItem);
                    }
                }

                _context.Feeds.ReplaceOne<FeedDocument>(x => x.Name == result.Name, result);
            }

            return feedItems;
        }
Exemplo n.º 3
0
 // POST: api/FeedItem
 public void Post(FeedItem feedItem)
 {
 }