public void Create(IEnumerable <Product> orderItems, ShippingInfo shippingInfo) { var subtotal = 0m; foreach (var item in orderItems) { ApplyChange(OrderItemAddedEvent.Raise(Id, item.Id, item.ItemName, item.UnitPrice)); subtotal += item.UnitPrice; } ApplyChange(ShippingInfoUpdatedEvent.Raise(Id, shippingInfo.ContactName, shippingInfo.ContactPhone, shippingInfo.ShippingAddress)); ApplyChange(OrderCreatedEvent.Raise(Id, subtotal)); }
public override void ApplyChange(IDomainEvent @event, bool isRebuild = false) { base.ApplyChange(@event, isRebuild); switch (@event) { case OrderItemAddedEvent orderItemAdded: OrderItems.Add(Product.NewProduct(orderItemAdded.ProductId, orderItemAdded.ItemName, orderItemAdded.UnitPrice)); break; case ShippingInfoUpdatedEvent shippingInfoUpdated: ShippingInfo = ShippingInfo.NewShippingInfo(shippingInfoUpdated.ContactName, shippingInfoUpdated.ContactPhone, shippingInfoUpdated.ShippingAddress); break; case OrderCreatedEvent orderCreatedEvent: Subtotal = orderCreatedEvent.Subtotal; break; } }