public async Task <ActionResult <OrderDto> > Post(OrderDto orderDto) { Order order = orderDto.MapToOrder(); await _orderService.Create(order); return(Created($"/api/orders/{order.OrderId}", order)); }
public async Task CheckoutOrder(OrderDto sessionOrder, Customer customer) { // Convert from DTO Order order = sessionOrder.MapToOrder(); // Set missing properties order.Customer = customer; order.OrderLines.ForEach(l => l.UnitCostPrice = GetCostPrice(l.ProductId)); // Needs the Product navigation property set before saving, // otherwise the line total is not calculated. order.OrderLines.ForEach(l => l.Product = _context.Products.Find(l.ProductId)); _context.Orders.Add(order); await _context.SaveChangesAsync(); }