diff --git a/docs/architecture/modern-web-apps-azure/work-with-data-in-asp-net-core-apps.md b/docs/architecture/modern-web-apps-azure/work-with-data-in-asp-net-core-apps.md index a1ead57407637..902d10a3f7e72 100644 --- a/docs/architecture/modern-web-apps-azure/work-with-data-in-asp-net-core-apps.md +++ b/docs/architecture/modern-web-apps-azure/work-with-data-in-asp-net-core-apps.md @@ -159,7 +159,8 @@ public class Basket : BaseEntity public void AddItem(int catalogItemId, decimal unitPrice, int quantity = 1) { - if (!Items.Any(i => i.CatalogItemId == catalogItemId)) + var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId); + if (existingItem == null) { _items.Add(new BasketItem() { @@ -167,10 +168,8 @@ public class Basket : BaseEntity Quantity = quantity, UnitPrice = unitPrice }); - return; - } - var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId); - existingItem.Quantity += quantity; + } + else existingItem.Quantity += quantity; } } ```