Example #1
0
        public async Task <List <Story> > GetNewStoriesAsync()
        {
            List <Story> stories = new List <Story>();

            var response = await _repository.GetNewStoriesAsync();

            if (response.IsSuccessStatusCode)
            {
                var storiesResponse = response.Content.ReadAsStringAsync().Result;
                var bestIds         = JsonConvert.DeserializeObject <List <int> >(storiesResponse);

                var tasks = bestIds.Select(GetStoryAsync);
                stories = (await Task.WhenAll(tasks)).ToList();
            }
            return(stories);
        }
        public async Task <List <Story> > GetNewStoriesAsync(string searchTerm)
        {
            List <Story> stories = new List <Story>();

            var response = await _repository.GetNewStoriesAsync();

            if (response.IsSuccessStatusCode)
            {
                var storiesResponse = response.Content.ReadAsStringAsync().Result;
                var bestIds         = JsonConvert.DeserializeObject <List <int> >(storiesResponse);

                var tasks = bestIds.Select(GetStoryAsync);
                stories = (await Task.WhenAll(tasks)).ToList();

                if (!String.IsNullOrEmpty(searchTerm))
                {
                    var search = searchTerm.ToLower();
                    stories = stories.Where(s =>
                                            s.Title.ToLower().IndexOf(search) > -1 || s.By.ToLower().IndexOf(search) > -1)
                              .ToList();
                }
            }
            return(stories);
        }