Paging infrastructure implemented through specifications. (#151)

* Paging criterias added in BaseSpecification. New paginated specification added (CatalogFilterPaginatedSpecification) . EFRepository cleaned up and paging implementation added. Usage of the new paging infrastructure in CatalogService (Web and WebRazor).

* Use IReadOnlyList<T> instead of List<T> as return type from repositories.

* - Ordering possibility added in the specification.
- Evaluation of the specification placed in separate class.
This commit is contained in:
Fati Iseni
2018-11-09 07:46:58 +01:00
committed by Steve Smith
parent 156d5c6b25
commit 04530db118
9 changed files with 114 additions and 46 deletions

View File

@@ -43,14 +43,12 @@ namespace Microsoft.eShopWeb.RazorPages.Services
_logger.LogInformation("GetCatalogItems called.");
var filterSpecification = new CatalogFilterSpecification(brandId, typeId);
var root = _itemRepository.List(filterSpecification);
var filterPaginatedSpecification =
new CatalogFilterPaginatedSpecification(itemsPage * pageIndex, itemsPage, brandId, typeId);
var totalItems = root.Count();
var itemsOnPage = root
.Skip(itemsPage * pageIndex)
.Take(itemsPage)
.ToList();
// the implementation below using ForEach and Count. We need a List.
var itemsOnPage = _itemRepository.List(filterPaginatedSpecification).ToList();
var totalItems = _itemRepository.Count(filterSpecification);
itemsOnPage.ForEach(x =>
{