public class PlaceOrderHandler : IHandleMessages<PlaceOrder> | |
{ | |
private readonly SalesDbContext _dbContext; | |
private readonly IWarehouseInventory _warehouseInventory; | |
public PlaceOrderHandler(SalesDbContext dbContext, IWarehouseInventory warehouseInventory) | |
{ | |
_dbContext = dbContext; | |
_warehouseInventory = warehouseInventory; | |
} | |
public async Task Handle(PlaceOrder message, IMessageHandlerContext context) | |
{ | |
if (_warehouseInventory.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