Skip to content

Instantly share code, notes, and snippets.

@explorer14
Last active Nov 28, 2021
Embed
What would you like to do?
public async Task Handle(ProductStockChanged stockChangedEvent)
{
var product = await productRepository.GetBy(stockChangedEvent.ProductId);
var purchaseOrderLine = await purchaseOrderLineRepository.GetBy(stockChangedEvent.PurchaseOrderLineId);
// validation...
if (stockChangedEvent.IsStockRaised)
{
// OOPSIES ⬇️
product.Stock += stockChangedEvent.Quantity;
purchaseOrderLine.QuantityDelivered += stockChangedEvent.Quantity;
await purchaseOrderLineRepository.Update(purchaseOrderLine);
await productRepository.Save(product);
}
else
product.Stock -= stockChangedEvent.Quantity; // stock decrements don't affect purchase deliveries
// trigger a use case that depends on updated product and purchase order line
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment