/// <summary> /// Add order and order details /// </summary> /// <param name="order"></param> /// <returns></returns> public async Task AddOrderAsync(Order order) { //Insert order first Order newOrder = new Order { OrderConformationNumber = _orderHelper.GenerateOrderConformationNumber(), OrderedDate = DateTime.Now, OrderStatusId = (int)OrderStausEnum.ACTIVE, CustomerId = order.CustomerId }; await _orderRepository.AddOrderAsync(newOrder); //Get newly insterted orderID int id = newOrder.ID; //Insert all the order details foreach (var orderDetail in order.OrderDetails) { OrderDetail newOrderDetail = new OrderDetail { Quantity = orderDetail.Quantity, OrderId = id, ItemId = orderDetail.ItemId, VendorId = orderDetail.VendorId, OrderDetailStatusId = (int)OrderDetailStausEnum.ACTIVE }; await _orderDetailRepository.AddOrderDetailAsync(newOrderDetail); } }
public async Task <IActionResult> Post([FromBody] OrderDetail orderDetail) { var newOrderDetail = await _orderDetailRepository.AddOrderDetailAsync(orderDetail); return(Ok(newOrderDetail)); }