-
-
Save dcomartin/4195ef53cfaea46382e6558673da026e 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 class PlaceOrderHandler : IHandleMessages<PlaceOrder> | |
{ | |
private readonly SalesDbContext _dbContext; | |
private readonly WarehouseInventoryQuery.DoAllProductsHaveQtyOnHand _doAllProductsHaveQtyOnHand; | |
public PlaceOrderHandler(SalesDbContext dbContext, WarehouseInventoryQuery.DoAllProductsHaveQtyOnHand doAllProductsHaveQtyOnHand) | |
{ | |
_dbContext = dbContext; | |
_doAllProductsHaveQtyOnHand = doAllProductsHaveQtyOnHand; | |
} | |
public async Task Handle(PlaceOrder message, IMessageHandlerContext context) | |
{ | |
if (_doAllProductsHaveQtyOnHand(message.OrderId) == false) | |
{ | |
return; | |
} | |
await _dbContext.Orders.AddAsync(new Order | |
{ | |
OrderId = message.OrderId, | |
Status = OrderStatus.Pending | |
}); | |
await _dbContext.SaveChangesAsync(); | |
var orderPlaced = new OrderPlaced | |
{ | |
OrderId = message.OrderId | |
}; | |
await context.Publish(orderPlaced); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment