public BasketItemAdded(Guid aggregateRootId, Guid productId, string productName, UnitQuantity quantity, Price price) : base(aggregateRootId) { ProductId = productId; ProductName = productName; Price = price; Quantity = quantity; }
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); }
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); }
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); }
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); }
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); }
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; }
internal Product RemoveFromStock(UnitQuantity quantity) { Raise(new ProductQuantityRemoved(Id, quantity)); return(this); }
internal Product AddToStock(UnitQuantity quantity) { Raise(new ProductQuantityAdded(Id, quantity)); return(this); }
internal Product SetQuantity(UnitQuantity target) { Raise(new ProductQuantityChanged(Id, target)); return(this); }
private void Apply(ReservedProductPurchased e) { Reserved = Reserved.Subtract(e.Quantity); }
private void Apply(ProductReservationCancelled e) { Reserved = Reserved.Subtract(e.Quantity); Quantity = Quantity.Add(e.Quantity); }
public OrderLine SubtractQuantity(UnitQuantity quantity) { return(new OrderLine(ProductId, ProductName, Price, Quantity.Subtract(quantity))); }
public OrderLine AddQuantity(UnitQuantity quantity) { return(new OrderLine(ProductId, ProductName, Price, Quantity.Add(quantity))); }
public ProductReserved(Guid aggregateRootId, UnitQuantity quantity) : base(aggregateRootId) { Quantity = quantity; }
public ProductReservationFailed(Guid aggregateRootId, UnitQuantity quantity, Reason failedReason) : base(aggregateRootId) { Quantity = quantity; FailedReason = failedReason; }
public ProductQuantityChanged(Guid aggregateRootId, UnitQuantity target) : base(aggregateRootId) { Target = target; }
public BasketItemRemoved(Guid aggregateRootId, Guid productId, UnitQuantity quantity) : base(aggregateRootId) { ProductId = productId; Quantity = quantity; }
internal PendingBasket AddItem(Guid productId, string productName, UnitQuantity quantity, Price price) { Raise(new BasketItemAdded(Id, productId, productName, quantity, price)); return(this); }