using System; namespace EventSourcing.Demo { public class WarehouseProductEntity { public string Sku { get; set; } public int QuantityOnHand { get; set; } public DateTime Shipped { get; set; } public DateTime Received { get; set; } private readonly WarehouseProductState _warehouseProductState = new(); public WarehouseProductEntity(string sku) { Sku = sku; } public void ShipProduct(int quantity) { if (quantity > _warehouseProductState.QuantityOnHand) { throw new InvalidDomainException("Cannot Ship to a negative Quantity on Hand."); } Shipped = DateTime.UtcNow; QuantityOnHand -= quantity; } public void ReceiveProduct(int quantity) { Received = DateTime.UtcNow; QuantityOnHand += quantity; } public void AdjustInventory(int quantity) { if (_warehouseProductState.QuantityOnHand + quantity < 0) { throw new InvalidDomainException("Cannot adjust to a negative Quantity on Hand."); } QuantityOnHand += quantity; } } }