public async Task <IActionResult> Index(int?id)
        {
            // Null-coalescing operator
            // If id is not null set page to it, or if null use 1
            int              page     = id ?? 1; // id is the page number coming in
            const int        PageSize = 3;
            List <VideoGame> games    = await VideoGameDb.GetGamesByPage(_context, page, PageSize);

            int totalPages = await VideoGameDb.GetTotalPages(_context, PageSize);

            ViewData["Pages"]       = totalPages;
            ViewData["CurrentPage"] = page;

            return(View(games));
        }
        [HttpGet] // made id optional using ?
        public async Task <IActionResult> Index(int?id)
        {
            // id is the page number coming in
            // null-coalescing operator = if id is not null, set page to it. if null, use 1
            int              page     = id ?? 1;
            const int        PageSize = 3;
            List <VideoGame> games    = await VideoGameDb.GetGamesByPage(_context, page, PageSize);


            int totalPages = await VideoGameDb.GetTotalPages(_context, PageSize);

            ViewData["Pages"]       = totalPages;
            ViewData["CurrentPage"] = page;
            // the view as access to all of the data
            return(View(games));
        }
예제 #3
0
        public async Task <IActionResult> Index(int?id)
        {
            //Null-coalescing operator
            //id is the page number coming in
            int       page      = id ?? 1; //if the id is not null, it sets page to it. If it's null, use 1.
            const int PAGE_SIZE = 3;

            List <VideoGame> games = await VideoGameDb.GetGamesByPage(_context, page, PAGE_SIZE);

            int totalPages = await VideoGameDb.GetTotalPages(_context, PAGE_SIZE);

            ViewData["Pages"]       = totalPages;
            ViewData["CurrentPage"] = page;

            return(View(games));
        }
예제 #4
0
        public async Task <IActionResult> Index(int?id)
        {
            //Null-coalescing operator
            // If id is not null set page to it, or if null start with one.
            int page = id ?? 1; // id is the page number coming in
            //Create a list of all VG in database for display purposes
            const int        PageSize = 3;
            List <VideoGame> games    = await VideoGameDb.GetGamesByPage(_context, page, PageSize);

            //Maximum page
            int totalPages =
                await VideoGameDb.GetTotalPages(_context, PageSize);

            ViewData["Pages"]       = totalPages;
            ViewData["CurrentPage"] = page;
            return(View(games));
        }