public void AddProduct(Guid productId, int quantity) { ShoppingCartItem item = _items.FirstOrDefault(i => i.ProductId == productId); if (item == null) { var e = new ProductAddedToShoppingCart(Id, productId, quantity); ApplyEvent(e); } else { int newQuantity = item.Quantity + quantity; ChangeProductQuanity(productId, newQuantity); } }
private void Apply(ProductAddedToShoppingCart @event) => BasketItems.Add(new BasketItem(@event.Product, @event.Qty));
private void ProductAddedToShoppingCartEventHandler(ProductAddedToShoppingCart e) { var item = new ShoppingCartItem(e.ProductId, e.Quantity); _items.Add(item); }