示例#1
0
        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));
示例#3
0
 private void ProductAddedToShoppingCartEventHandler(ProductAddedToShoppingCart e)
 {
     var item = new ShoppingCartItem(e.ProductId, e.Quantity);
     _items.Add(item);
 }