Exemple #1
0
        public async Task <ActionResult> Index(int?page)
        {
            if (page == null)
            {
                page = 1;
            }
            //string hnBaseUrl = ConfigurationManager.AppSettings["HNBaseUrl"];

            //int pageSize = int.Parse(ConfigurationManager.AppSettings["PageSize"].ToString());

            _hackerNewsService.SetHNBaseUrl(HnBaseUrl);
            StoryRepo storyRepo = new StoryRepo(_hackerNewsService, HnBaseUrl);

            int[] storyIds = await storyRepo.GetBestStoryIds();

            ViewBag.NumOfPages = Math.Ceiling((double)storyIds.Length / PageSize);

            ViewBag.CurrentPageNumber = page;

            int[] currentStoryIds = storyIds
                                    .Skip((page.Value - 1) * PageSize)
                                    .Take(PageSize)
                                    .ToArray();

            StoryCollection colStory = await storyRepo.GetBestStories(currentStoryIds);

            return(View(colStory));
        }