add FirstAsync in respository (#370)

* add FirstAsync in respository

* use new FirstOrDefaultAsync() method from repository
This commit is contained in:
Cédric Michel
2020-05-05 16:23:57 +02:00
committed by GitHub
parent 7dcf3845d6
commit fdb4869c0b
4 changed files with 15 additions and 4 deletions

View File

@@ -13,5 +13,7 @@ namespace Microsoft.eShopWeb.ApplicationCore.Interfaces
Task UpdateAsync(T entity);
Task DeleteAsync(T entity);
Task<int> CountAsync(ISpecification<T> spec);
Task<T> FirstAsync(ISpecification<T> spec);
Task<T> FirstOrDefaultAsync(ISpecification<T> spec);
}
}

View File

@@ -39,7 +39,7 @@ namespace Microsoft.eShopWeb.ApplicationCore.Services
{
Guard.Against.NullOrEmpty(userName, nameof(userName));
var basketSpec = new BasketWithItemsSpecification(userName);
var basket = (await _basketRepository.ListAsync(basketSpec)).FirstOrDefault();
var basket = (await _basketRepository.FirstOrDefaultAsync(basketSpec));
if (basket == null)
{
_logger.LogInformation($"No basket found for {userName}");
@@ -72,7 +72,7 @@ namespace Microsoft.eShopWeb.ApplicationCore.Services
Guard.Against.NullOrEmpty(anonymousId, nameof(anonymousId));
Guard.Against.NullOrEmpty(userName, nameof(userName));
var basketSpec = new BasketWithItemsSpecification(anonymousId);
var basket = (await _basketRepository.ListAsync(basketSpec)).FirstOrDefault();
var basket = (await _basketRepository.FirstOrDefaultAsync(basketSpec));
if (basket == null) return;
basket.SetNewBuyerId(userName);
await _basketRepository.UpdateAsync(basket);