From aa4002de2b403381f06949f12d01aa3cde91399f Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Sat, 21 Aug 2021 16:53:18 +1000 Subject: [PATCH] 7.5 Adding Pagination; e.g. 7.14 Adding Pagination Support to the Product Controller List Method --- .../SportsStore.WebUI/Controllers/ProductController.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/SportsStore/SportsStore.WebUI/Controllers/ProductController.cs b/SportsStore/SportsStore.WebUI/Controllers/ProductController.cs index dd145a1..78c0321 100644 --- a/SportsStore/SportsStore.WebUI/Controllers/ProductController.cs +++ b/SportsStore/SportsStore.WebUI/Controllers/ProductController.cs @@ -9,6 +9,8 @@ namespace SportsStore.WebUI.Controllers { public class ProductController : Controller { + public int PageSize = 4; // We will change this later + private IProductRepository repository; public ProductController(IProductRepository productRepository) @@ -16,9 +18,12 @@ namespace SportsStore.WebUI.Controllers repository = productRepository; } - public ViewResult List() + public ViewResult List(int page = 1) { - return View(repository.Products); + return View(repository.Products + .OrderBy(p => p.ProductID) + .Skip((page - 1) * PageSize) + .Take(PageSize)); } } } \ No newline at end of file