Exemplo n.º 1
0
        public void AddItem(OrderItem item, IProductInfo product)
        {
            switch (_state)
            {
                case OrderState.Cancelled:
                    throw new InvalidStateException(
                        "You can't add an item. This order is already cancelled. Place a new order.");
                case OrderState.Paid:
                    throw new InvalidStateException("You can't change this order. It's already paid. Place a new order.");
            }

            var priceForNewItem = item.Quantity*product.Price;
            var e = new OrderItemAdded(
                Id,
                _location,
                _items.ToArray(),
                item,
                _price + priceForNewItem);
            ApplyChange(e);
        }
Exemplo n.º 2
0
 private void Apply(OrderItemAdded e)
 {
     _price = e.Price;
     _items.Add(e.AddedItem);
 }