public async Task <ActionResult <int> > Add(AddOrderInputDto model) { log.LogInformation("Adding order for customer {0}", model.CustomerName); var orderId = await ordersService.AddOrder(model); return(CreatedAtAction(nameof(Get), new { id = orderId }, new { id = orderId })); }
public async Task <int> AddOrder(AddOrderInputDto dto) { Order order = new Order() { CustomerName = dto.CustomerName, IsShipped = dto.IsShipped, ShipperCity = dto.ShipperCity }; using (OrdersDbContext dbContext = new OrdersDbContext() { ConnectionString = _connectionString }) { dbContext.Orders.Add(order); await dbContext.SaveChangesAsync(); return(order.OrderID); } }