From 96e16ca3e76b4f37a45b0699e1279f2559ce83d7 Mon Sep 17 00:00:00 2001 From: Moien Tajik Date: Sat, 19 Oct 2019 01:27:42 +0330 Subject: [PATCH] Made AddAsync method fully asynchronous --- src/Infrastructure/Data/EfRepository.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Infrastructure/Data/EfRepository.cs b/src/Infrastructure/Data/EfRepository.cs index db05a27..830b89f 100644 --- a/src/Infrastructure/Data/EfRepository.cs +++ b/src/Infrastructure/Data/EfRepository.cs @@ -1,6 +1,6 @@ -using Microsoft.eShopWeb.ApplicationCore.Interfaces; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.eShopWeb.ApplicationCore.Entities; +using Microsoft.eShopWeb.ApplicationCore.Interfaces; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -20,12 +20,12 @@ namespace Microsoft.eShopWeb.Infrastructure.Data { _dbContext = dbContext; } - + public virtual async Task GetByIdAsync(int id) { return await _dbContext.Set().FindAsync(id); } - + public async Task> ListAllAsync() { return await _dbContext.Set().ToListAsync(); @@ -35,7 +35,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data { return await ApplySpecification(spec).ToListAsync(); } - + public async Task CountAsync(ISpecification spec) { return await ApplySpecification(spec).CountAsync(); @@ -43,27 +43,27 @@ namespace Microsoft.eShopWeb.Infrastructure.Data public async Task AddAsync(T entity) { - _dbContext.Set().Add(entity); + await _dbContext.Set().AddAsync(entity); await _dbContext.SaveChangesAsync(); return entity; } - + public async Task UpdateAsync(T entity) { _dbContext.Entry(entity).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); } - + 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); - } + } } -} +} \ No newline at end of file