Browse Source

Reformatting

main
Steve Smith 7 years ago
committed by GitHub
parent
commit
1fe6becfcc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      src/Infrastructure/Data/EfRepository.cs

14
src/Infrastructure/Data/EfRepository.cs

@ -20,10 +20,6 @@ namespace Microsoft.eShopWeb.Infrastructure.Data
{
_dbContext = dbContext;
}
private IQueryable<T> ApplySpecification(ISpecification<T> spec)
{
return SpecificationEvaluator<T>.GetQuery(_dbContext.Set<T>().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<T> GetByIdAsync(int id)
{
return await _dbContext.Set<T>().FindAsync(id);
@ -59,10 +54,12 @@ namespace Microsoft.eShopWeb.Infrastructure.Data
{
return await ApplySpecification(spec).ToListAsync();
}
public int Count(ISpecification<T> spec)
{
return ApplySpecification(spec).Count();
}
public async Task<int> CountAsync(ISpecification<T> 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<T>().Remove(entity);
_dbContext.SaveChanges();
}
public async Task DeleteAsync(T entity)
{
_dbContext.Set<T>().Remove(entity);
await _dbContext.SaveChangesAsync();
}
private IQueryable<T> ApplySpecification(ISpecification<T> spec)
{
return SpecificationEvaluator<T>.GetQuery(_dbContext.Set<T>().AsQueryable(), spec);
}
}
}

Loading…
Cancel
Save