Browse Source

Removing List and all the places it was used

main
Eric Fleming 7 years ago
parent
commit
b084d4e770
  1. 1
      src/ApplicationCore/Interfaces/IRepository.cs
  2. 14
      src/Web/Services/CatalogService.cs

1
src/ApplicationCore/Interfaces/IRepository.cs

@ -6,7 +6,6 @@ namespace Microsoft.eShopWeb.ApplicationCore.Interfaces
public interface IRepository<T> where T : BaseEntity public interface IRepository<T> where T : BaseEntity
{ {
T GetSingleBySpec(ISpecification<T> spec); T GetSingleBySpec(ISpecification<T> spec);
IEnumerable<T> List(ISpecification<T> spec);
T Add(T entity); T Add(T entity);
void Update(T entity); void Update(T entity);
void Delete(T entity); void Delete(T entity);

14
src/Web/Services/CatalogService.cs

@ -18,14 +18,14 @@ namespace Microsoft.eShopWeb.Web.Services
public class CatalogService : ICatalogService public class CatalogService : ICatalogService
{ {
private readonly ILogger<CatalogService> _logger; private readonly ILogger<CatalogService> _logger;
private readonly IRepository<CatalogItem> _itemRepository; private readonly IAsyncRepository<CatalogItem> _itemRepository;
private readonly IAsyncRepository<CatalogBrand> _brandRepository; private readonly IAsyncRepository<CatalogBrand> _brandRepository;
private readonly IAsyncRepository<CatalogType> _typeRepository; private readonly IAsyncRepository<CatalogType> _typeRepository;
private readonly IUriComposer _uriComposer; private readonly IUriComposer _uriComposer;
public CatalogService( public CatalogService(
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IRepository<CatalogItem> itemRepository, IAsyncRepository<CatalogItem> itemRepository,
IAsyncRepository<CatalogBrand> brandRepository, IAsyncRepository<CatalogBrand> brandRepository,
IAsyncRepository<CatalogType> typeRepository, IAsyncRepository<CatalogType> typeRepository,
IUriComposer uriComposer) IUriComposer uriComposer)
@ -46,13 +46,13 @@ namespace Microsoft.eShopWeb.Web.Services
new CatalogFilterPaginatedSpecification(itemsPage * pageIndex, itemsPage, brandId, typeId); new CatalogFilterPaginatedSpecification(itemsPage * pageIndex, itemsPage, brandId, typeId);
// the implementation below using ForEach and Count. We need a List. // the implementation below using ForEach and Count. We need a List.
var itemsOnPage = _itemRepository.List(filterPaginatedSpecification).ToList(); var itemsOnPage = await _itemRepository.ListAsync(filterPaginatedSpecification);
var totalItems = _itemRepository.Count(filterSpecification); var totalItems = await _itemRepository.CountAsync(filterSpecification);
itemsOnPage.ForEach(x => foreach (var itemOnPage in itemsOnPage)
{ {
x.PictureUri = _uriComposer.ComposePicUri(x.PictureUri); itemOnPage.PictureUri = _uriComposer.ComposePicUri(itemOnPage.PictureUri);
}); }
var vm = new CatalogIndexViewModel() var vm = new CatalogIndexViewModel()
{ {

Loading…
Cancel
Save