public static void Handle(ProductItemAddedToShoppingCart @event, ShoppingCartDetails view) { var productItem = @event.ProductItem; var existingProductItem = view.ProductItems .FirstOrDefault(x => x.ProductId == @event.ProductItem.ProductId); if (existingProductItem == null) { view.ProductItems.Add(new ShoppingCartDetailsProductItem { ProductId = productItem.ProductId, Quantity = productItem.Quantity, UnitPrice = productItem.UnitPrice }); } else { existingProductItem.Quantity += productItem.Quantity; } view.Version++; }
public static void Handle(ProductItemAddedToShoppingCart @event, ShoppingCartShortInfo view) { view.TotalItemsCount += @event.ProductItem.Quantity; view.TotalPrice += @event.ProductItem.TotalPrice; view.Version++; }