コード例 #1
0
        public async Task <ActionResult> Index()
        {
            try
            {
                var stories = await hackerNewsSvc.GetBestStories();

                return(View(stories));
            }
            catch (Exception)
            {
                ViewBag.error = "There was a problem retrieving the stories.";
                return(View(new List <Story>()));
            }
        }
コード例 #2
0
        public async Task <IActionResult> GetBestStories([FromQuery] int size = 20)
        {
            var stories = await _hackerNewsService.GetBestStories(size);

            if (stories.IsNullOrEmpty())
            {
                return(NoContent());
            }

            var storiesDto = stories.Select(x => new HackerStoryDto
            {
                Title        = x.Title,
                Uri          = x.Url,
                PostedBy     = x.By,
                Time         = x.GetTime(),
                Score        = x.Score,
                CommentCount = x.Descendants
            });

            return(Ok(storiesDto));
        }
コード例 #3
0
 public async Task <IActionResult> Get()
 {
     return(CustomResponse(await _hackerNewsService.GetBestStories()));
 }
コード例 #4
0
 public Task <IEnumerable <Article> > Get()
 {
     return(_service.GetBestStories());
 }
コード例 #5
0
        public async Task <ActionResult <IEnumerable <Story> > > Get()
        {
            var stories = await _newsService.GetBestStories(_numberOfStories);

            return(new ActionResult <IEnumerable <Story> >(stories));
        }