Пример #1
0
        public async Task <IActionResult> GetOriginalTweets()
        {
            try
            {
                var tweets = await TweetService.GetAsync(tweetSettings);

                var json = JsonConvert.SerializeObject(tweets);

                return(new OkObjectResult(json));
            }
            catch (Exception e)
            {
                logger.LogCritical(e, "Unhandled error while getting original tweets");
                return(new ObjectResult(e)
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
Пример #2
0
        private async Task <IActionResult> GetOriginalTweets(
            List <string> communities
            )
        {
            try
            {
                communities ??= defaultCommunities;

                var allCommunities = (await realmSettings.GetAllCommunitiesAsync(SocialMediaType.Twitter))
                                     .Select(x => x.Community.Name).ToList();

                var allTweets = await CacheHelper.PostsCache.GetOrCreateAsync("tweets",
                                                                              async() => await TweetService.GetAsync(this.tweetSettings,
                                                                                                                     allCommunities));

                var tweets = new List <ISocialPost>();
                foreach (var community in communities)
                {
                    tweets.AddRange(allTweets.Where(x =>
                                                    x.CommunityGroupId.Equals(community, StringComparison.InvariantCultureIgnoreCase)));
                }

                var json = JsonConvert.SerializeObject(tweets);

                return(new OkObjectResult(json));
            }
            catch (Exception e)
            {
                logger.LogCritical(e, "Unhandled error while getting original tweets");
                return(new ObjectResult(e)
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }