public async Task <IActionResult> ShowAll(int?page) //variable name need to match asp-route name, use a nullable int because don't have a page to begin with
        {
            const int PageSize   = 2;
            int       pageNumber = page.HasValue ? page.Value : 1;

            ViewData["CurrentPage"] = pageNumber;

            int maxPage = await GetMaxPage(PageSize);

            ViewData["MaxPage"] = maxPage;

            List <Clothing> clothes = await ClothingDb.GetClothingByPage(_context, pageNumber, PageSize); //database context is injected by the framework using the constructor makes it so you do have to create new database objects everyone you need it

            return(View(clothes));
        }
Example #2
0
        public async Task <IActionResult> ShowAll(int?page)
        {
            const int PageSize = 2;
            // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator
            int pageNumber = page ?? 1;

            ViewData["CurrentPage"] = pageNumber;

            int maxPage = await GetMaxPage(PageSize);

            ViewData["MaxPage"] = maxPage;

            List <Clothing> clothes = await ClothingDb.GetClothingByPage(_context, pageNum : pageNumber, pageSize : PageSize);

            return(View(clothes));
        }
Example #3
0
        public async Task <IActionResult> ShowAll(int?page)
        {
            const int PageSize = 2;
            // Null-coalescing operator ??
            int pageNumber = page ?? 1; //use page number, if not there use 1, C# Null coalescing Operator, look it up

            ViewData["CurrentPage"] = pageNumber;

            int maxPage = await GetMaxPage(PageSize);

            ViewData["MaxPage"] = maxPage;

            // Just a placeholder ...
            List <Clothing> clothes =
                await ClothingDb.GetClothingByPage(_context, pageNum : pageNumber, pageSize : PageSize);

            return(View(clothes));
        }
        public async Task <IActionResult> ShowAll(int?page)
        {
            const int PageSize = 2;
            // if page is not null, use its value... otherwise use 1
            // int pageNumber = page.HasValue ? page.Value : 1;
            // NUll
            int pageNumber = page ?? 1; // same as above

            ViewData["CurrentPage"] = pageNumber;

            int maxPage = await GetMaxPage(PageSize);

            ViewData["MaxPage"] = maxPage;

            List <Clothing> clothes = await ClothingDb.GetClothingByPage(_context, pageNum : pageNumber, pageSize : PageSize);

            return(View(clothes));
        }
Example #5
0
        public async Task <IActionResult> ShowAll(int?page) //page comes from "asp-route-page" in the ShowAll.cshtml (located in pagination ul)
        {
            const int PAGE_SIZE = 2;

            // Null-coalescing operator: ??
            // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator
            int pageNumber = page ?? 1;

            ViewData["CurrentPage"] = pageNumber;

            int maxPage = await GetMaxPage(PAGE_SIZE);

            ViewData["MaxPage"] = maxPage;

            List <Clothing> clothes = await ClothingDb.GetClothingByPage(_context, pageNum : pageNumber, pageSize : PAGE_SIZE);

            return(View(clothes));
        }