public void AddOrderDetails(Order order, Cart cart) { var cartItems = cart.lineCollection.ToList(); foreach (var item in cartItems) { var orderDetail = new OrderDetail { OrderId = order.OrderId, ProductId = item.Product.ProductId, Quantity = item.Quantity }; db.OrderDetails.Add(orderDetail); } db.SaveChanges(); }
public void CreateOrder(Order order) { decimal orderTotal = 0; List<Cart> cartItems = GetCartItems(); // Iterate over the items in the cart, adding the order details for each foreach (Cart item in cartItems) { var orderDetail = new OrderDetail { ProductId = item.ProductId, OrderId = order.Id, UnitPrice = item.Product.Price, Quantity = item.Count }; // Set the order total of the shopping cart orderTotal += (item.Count*item.Product.Price); _storetUnitOfWork.OrderDetails.Add(orderDetail); } // Set the order's total to the orderTotal count order.Total = orderTotal; _storetUnitOfWork.Commit(); EmptyCart(); }