public async Task <IActionResult> PlaceOrder([FromBody] CreateOrderCommand createOrderCommand) { var tasks = createOrderCommand.OrderItems .Select(item => _productQueries.GetProductBySKUAsync(item.SKU) .ContinueWith((productAsync) => { var product = productAsync.Result; if (product != null) { item.ProductId = product.Id; item.UnitPrice = product.UnitPrice; item.ProductName = product.ProductName; } })); await Task.WhenAll(tasks); var commandResult = await _mediator.Send(createOrderCommand); if (!commandResult) { return(BadRequest()); } return(Ok()); }
public async Task <ActionResult <bool> > Post([FromBody] CreateOrderCommand createOrderCommand) { foreach (var item in createOrderCommand.OrderItems) { var product = await _productQueries.GetProductBySKUAsync(item.SKU); if (product != null) { item.ProductId = product.Id; item.UnitPrice = product.UnitPrice; } } return(await _mediator.Send(createOrderCommand)); }