Allow to remove items from the basket setting quantity to zero
This commit is contained in:
@@ -25,5 +25,10 @@ namespace Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate
|
||||
var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId);
|
||||
existingItem.Quantity += quantity;
|
||||
}
|
||||
|
||||
public void RemoveEmptyItems()
|
||||
{
|
||||
_items.RemoveAll(i => i.Quantity == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,10 +59,11 @@ namespace Microsoft.eShopWeb.ApplicationCore.Services
|
||||
{
|
||||
if (quantities.TryGetValue(item.Id.ToString(), out var quantity))
|
||||
{
|
||||
_logger.LogInformation($"Updating quantity of item ID:{item.Id} to {quantity}.");
|
||||
if(_logger != null) _logger.LogInformation($"Updating quantity of item ID:{item.Id} to {quantity}.");
|
||||
item.Quantity = quantity;
|
||||
}
|
||||
}
|
||||
basket.RemoveEmptyItems();
|
||||
await _basketRepository.UpdateAsync(basket);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user