Skip to content

Commit

Permalink
adding specification for getting items (dotnet-architecture#403)
Browse files Browse the repository at this point in the history
* items specification

* adding specification for items
  • Loading branch information
yigith authored Jun 18, 2020
1 parent 40a1bb4 commit 2909132
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ApplicationCore/Services/BasketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public BasketService(IAsyncRepository<Basket> basketRepository,

public async Task AddItemToBasket(int basketId, int catalogItemId, decimal price, int quantity = 1)
{
var basket = await _basketRepository.GetByIdAsync(basketId);
var basketSpec = new BasketWithItemsSpecification(basketId);
var basket = await _basketRepository.FirstOrDefaultAsync(basketSpec);
Guard.Against.NullBasket(basketId, basket);

basket.AddItem(catalogItemId, price, quantity);

Expand Down Expand Up @@ -53,7 +55,8 @@ public async Task<int> GetBasketItemCountAsync(string userName)
public async Task SetQuantities(int basketId, Dictionary<string, int> quantities)
{
Guard.Against.Null(quantities, nameof(quantities));
var basket = await _basketRepository.GetByIdAsync(basketId);
var basketSpec = new BasketWithItemsSpecification(basketId);
var basket = await _basketRepository.FirstOrDefaultAsync(basketSpec);
Guard.Against.NullBasket(basketId, basket);

foreach (var item in basket.Items)
Expand Down

0 comments on commit 2909132

Please sign in to comment.