Allow to remove items from the basket setting quantity to zero

This commit is contained in:
Ovi
2019-09-11 09:16:00 -04:00
parent c370b8affb
commit 70e009bda2
7 changed files with 69 additions and 9 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);
}