Пример #1
0
        public async Task <IList <Tweet> > FetchAndUpdateLast100Tweets(CancellationToken ct = default)
        {
            // Create tasks.
            var dbTweetsTask     = _tweetDbRepository.GetLast100ToritoTweets(ct);
            var clientTweetsTask = _tweetClientRepository.GetLast100ToritoTweets(ct);

            // Results.
            var dbtweetsResult     = await dbTweetsTask;
            var dboTweets          = _mapper.Map <IList <Tweet> >(dbtweetsResult);
            var clientTweetsResult = await clientTweetsTask;

            // Compare client results with Dbo.
            var toAddDbTweets = clientTweetsResult.Except(dboTweets, new TweetEqualityComparerById()).ToList();

            // Add not added tweets to DB.
            var toAddDbTweetsDbo = _mapper.Map <IList <TweetDbo> >(toAddDbTweets);
            await _tweetDbRepository.AddList(toAddDbTweetsDbo);

            return(clientTweetsResult);
        }