public Task Handle(ShipItem command) { var item = Inventory[command.ProductId]; int orderQuantity = command.Quantity, shipQuantity; do { if (item.QuantityOnHand <= 0) { // restock the item Thread.Sleep(500); item.QuantityOnHand += 12; // cheaper by the dozen :) } shipQuantity = Math.Min(orderQuantity, item.QuantityOnHand); item.QuantityOnHand -= shipQuantity; var shipped = new ItemShipped { OrderId = command.OrderId, ProductId = command.ProductId, Quantity = shipQuantity }; Bus.PublishAsync(shipped); } while (shipQuantity > 0); return(Task.CompletedTask); }
public Task Handle(ItemShipped ev) { Console.WriteLine($"Shipped {ev.Quantity} of product {Warehouse.Inventory[ev.ProductId].Product.Name}"); return(Task.CompletedTask); }