diff --git a/src/Infrastructure/Data/EfRepository.cs b/src/Infrastructure/Data/EfRepository.cs index 4a0f624..4fe8c60 100644 --- a/src/Infrastructure/Data/EfRepository.cs +++ b/src/Infrastructure/Data/EfRepository.cs @@ -20,10 +20,6 @@ namespace Microsoft.eShopWeb.Infrastructure.Data { _dbContext = dbContext; } - private IQueryable ApplySpecification(ISpecification spec) - { - return SpecificationEvaluator.GetQuery(_dbContext.Set().AsQueryable(), spec); - } public virtual T GetById(int id) { @@ -35,7 +31,6 @@ namespace Microsoft.eShopWeb.Infrastructure.Data return List(spec).FirstOrDefault(); } - public virtual async Task GetByIdAsync(int id) { return await _dbContext.Set().FindAsync(id); @@ -59,10 +54,12 @@ namespace Microsoft.eShopWeb.Infrastructure.Data { return await ApplySpecification(spec).ToListAsync(); } + public int Count(ISpecification spec) { return ApplySpecification(spec).Count(); } + public async Task CountAsync(ISpecification spec) { return await ApplySpecification(spec).CountAsync(); @@ -89,6 +86,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data _dbContext.Entry(entity).State = EntityState.Modified; _dbContext.SaveChanges(); } + public async Task UpdateAsync(T entity) { _dbContext.Entry(entity).State = EntityState.Modified; @@ -100,10 +98,16 @@ namespace Microsoft.eShopWeb.Infrastructure.Data _dbContext.Set().Remove(entity); _dbContext.SaveChanges(); } + public async Task DeleteAsync(T entity) { _dbContext.Set().Remove(entity); await _dbContext.SaveChangesAsync(); } + + private IQueryable ApplySpecification(ISpecification spec) + { + return SpecificationEvaluator.GetQuery(_dbContext.Set().AsQueryable(), spec); + } } }