-
-
Save explorer14/f82bc57366b8edd27b877536045928f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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