예제 #1
0
파일: Order.cs 프로젝트: GunioRobot/cqrs
        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);
        }
예제 #2
0
파일: Order.cs 프로젝트: GunioRobot/cqrs
 private void Apply(OrderItemAdded e)
 {
     _price = e.Price;
     _items.Add(e.AddedItem);
 }