Ejemplo n.º 1
0
 public BasketItemAdded(Guid aggregateRootId, Guid productId, string productName, UnitQuantity quantity, Price price)
     : base(aggregateRootId)
 {
     ProductId   = productId;
     ProductName = productName;
     Price       = price;
     Quantity    = quantity;
 }
Ejemplo n.º 2
0
        internal Product CancelReservation(UnitQuantity quantity)
        {
            if (quantity.GreaterThan(Reserved))
            {
                throw new InvalidOperationException("how can one cancel a quantity greater than he booked?");
            }

            Raise(new ProductReservationCancelled(Id, quantity));

            return(this);
        }
Ejemplo n.º 3
0
        internal Product PurchaseReserved(UnitQuantity quantity)
        {
            if (quantity.GreaterThan(Reserved))
            {
                throw new InvalidOperationException("how can one purchase a quantity greater than he booked?");
            }

            Raise(new ReservedProductPurchased(Id, quantity));

            return(this);
        }
Ejemplo n.º 4
0
        public Product()
        {
            Quantity = new UnitQuantity(0);
            Reserved = new UnitQuantity(0);

            RegisterEventHandler <ProductCreated>(Apply);
            RegisterEventHandler <ProductQuantityChanged>(Apply);
            RegisterEventHandler <ProductQuantityAdded>(Apply);
            RegisterEventHandler <ProductQuantityRemoved>(Apply);
            RegisterEventHandler <ProductReserved>(Apply);
            RegisterEventHandler <ProductReservationCancelled>(Apply);
            RegisterEventHandler <ReservedProductPurchased>(Apply);
        }
Ejemplo n.º 5
0
        internal Product Reserve(UnitQuantity quantity)
        {
            if (Quantity.LessThan(quantity))
            {
                Raise(new ProductReservationFailed(Id, quantity, ProductReservationFailed.Reason.NotAvailable));
            }
            else
            {
                Raise(new ProductReserved(Id, quantity));
            }

            return(this);
        }
Ejemplo n.º 6
0
        internal PendingBasket RemoveItem(Guid productId, UnitQuantity quantity)
        {
            var lineIndex = Lines.FindIndex(l => l.ProductId == productId);

            if (lineIndex < 0)
            {
                throw new InvalidOperationException("can not remove item that not added");
            }
            if (Lines[lineIndex].Quantity.LessThan(quantity))
            {
                throw new InvalidOperationException("can not remove more than added");
            }

            Raise(new BasketItemRemoved(Id, productId, quantity));

            return(this);
        }
Ejemplo n.º 7
0
        public OrderLine(Guid productId, string productName, Price price, UnitQuantity quantity)
        {
            if (productId == Guid.Empty)
            {
                throw new ArgumentException("product id must not be empty");
            }
            if (string.IsNullOrEmpty(productName) || string.IsNullOrWhiteSpace(productName))
            {
                throw new ArgumentException("product name must not be empty");
            }
            if (price == null)
            {
                throw new ArgumentException("price must not be empty");
            }
            if (quantity == null)
            {
                throw new ArgumentException("quantity must not be empty");
            }

            ProductId   = productId;
            ProductName = productName;
            Price       = price;
            Quantity    = quantity;
        }
Ejemplo n.º 8
0
 internal Product RemoveFromStock(UnitQuantity quantity)
 {
     Raise(new ProductQuantityRemoved(Id, quantity));
     return(this);
 }
Ejemplo n.º 9
0
 internal Product AddToStock(UnitQuantity quantity)
 {
     Raise(new ProductQuantityAdded(Id, quantity));
     return(this);
 }
Ejemplo n.º 10
0
 internal Product SetQuantity(UnitQuantity target)
 {
     Raise(new ProductQuantityChanged(Id, target));
     return(this);
 }
Ejemplo n.º 11
0
 private void Apply(ReservedProductPurchased e)
 {
     Reserved = Reserved.Subtract(e.Quantity);
 }
Ejemplo n.º 12
0
 private void Apply(ProductReservationCancelled e)
 {
     Reserved = Reserved.Subtract(e.Quantity);
     Quantity = Quantity.Add(e.Quantity);
 }
Ejemplo n.º 13
0
 public OrderLine SubtractQuantity(UnitQuantity quantity)
 {
     return(new OrderLine(ProductId, ProductName, Price, Quantity.Subtract(quantity)));
 }
Ejemplo n.º 14
0
 public OrderLine AddQuantity(UnitQuantity quantity)
 {
     return(new OrderLine(ProductId, ProductName, Price, Quantity.Add(quantity)));
 }
Ejemplo n.º 15
0
 public ProductReserved(Guid aggregateRootId, UnitQuantity quantity)
     : base(aggregateRootId)
 {
     Quantity = quantity;
 }
Ejemplo n.º 16
0
 public ProductReservationFailed(Guid aggregateRootId, UnitQuantity quantity, Reason failedReason)
     : base(aggregateRootId)
 {
     Quantity     = quantity;
     FailedReason = failedReason;
 }
Ejemplo n.º 17
0
 public ProductQuantityChanged(Guid aggregateRootId, UnitQuantity target)
     : base(aggregateRootId)
 {
     Target = target;
 }
Ejemplo n.º 18
0
 public BasketItemRemoved(Guid aggregateRootId, Guid productId, UnitQuantity quantity)
     : base(aggregateRootId)
 {
     ProductId = productId;
     Quantity  = quantity;
 }
Ejemplo n.º 19
0
 internal PendingBasket AddItem(Guid productId, string productName, UnitQuantity quantity, Price price)
 {
     Raise(new BasketItemAdded(Id, productId, productName, quantity, price));
     return(this);
 }