Prevent negative item orders (#392)
* Pulling changes over from previous branch * Adding exception and guard clause
This commit is contained in:
@@ -55,12 +55,13 @@ namespace Microsoft.eShopWeb.ApplicationCore.Services
|
||||
Guard.Against.Null(quantities, nameof(quantities));
|
||||
var basket = await _basketRepository.GetByIdAsync(basketId);
|
||||
Guard.Against.NullBasket(basketId, basket);
|
||||
|
||||
foreach (var item in basket.Items)
|
||||
{
|
||||
if (quantities.TryGetValue(item.Id.ToString(), out var quantity))
|
||||
{
|
||||
if (_logger != null) _logger.LogInformation($"Updating quantity of item ID:{item.Id} to {quantity}.");
|
||||
item.SetNewQuantity(quantity);
|
||||
item.SetQuantity(quantity);
|
||||
}
|
||||
}
|
||||
basket.RemoveEmptyItems();
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace Microsoft.eShopWeb.ApplicationCore.Services
|
||||
var basket = await _basketRepository.FirstOrDefaultAsync(basketSpec);
|
||||
|
||||
Guard.Against.NullBasket(basketId, basket);
|
||||
Guard.Against.EmptyBasketOnCheckout(basket.Items);
|
||||
|
||||
var catalogItemsSpecification = new CatalogItemsSpecification(basket.Items.Select(item => item.CatalogItemId).ToArray());
|
||||
var catalogItems = await _itemRepository.ListAsync(catalogItemsSpecification);
|
||||
|
||||
Reference in New Issue
Block a user