/// <summary> /// Create a new OrderDetail object. /// </summary> /// <param name="orderDetailId">Initial value of the OrderDetailId property.</param> /// <param name="orderId">Initial value of the OrderId property.</param> /// <param name="albumId">Initial value of the AlbumId property.</param> /// <param name="quantity">Initial value of the Quantity property.</param> /// <param name="unitPrice">Initial value of the UnitPrice property.</param> public static OrderDetail CreateOrderDetail(global::System.Int32 orderDetailId, global::System.Int32 orderId, global::System.Int32 albumId, global::System.Int32 quantity, global::System.Decimal unitPrice) { OrderDetail orderDetail = new OrderDetail(); orderDetail.OrderDetailId = orderDetailId; orderDetail.OrderId = orderId; orderDetail.AlbumId = albumId; orderDetail.Quantity = quantity; orderDetail.UnitPrice = unitPrice; return orderDetail; }
/// <summary> /// Deprecated Method for adding a new object to the OrderDetails EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToOrderDetails(OrderDetail orderDetail) { base.AddObject("OrderDetails", orderDetail); }
public int CreateOrder(Order order) { decimal orderTotal = 0; var cartItems = GetCartItems(); //Iterate the items in the cart, adding Order Details for each foreach (var cartItem in cartItems) { var orderDetails = new OrderDetail { AlbumId = cartItem.AlbumId, OrderId = order.OrderId, UnitPrice = cartItem.Album.Price }; storeDB.OrderDetails.AddObject(orderDetails); orderTotal += (cartItem.Count * cartItem.Album.Price); } //Save the order storeDB.SaveChanges(); //Empty the shopping cart EmptyCart(); //Return the OrderId as a confirmation number return order.OrderId; }