public ActionResult Add(int bookId) { BookShopEntities db = new BookShopEntities(); var shoppingCart = GetShoppingCart(); var existingLine = shoppingCart.Lines.SingleOrDefault(l => l.Book.Id == bookId); if (existingLine != null) { existingLine.Quantity++; } else { var book = db.Books.First(b => b.Id == bookId); OrderLine newOrderLine = new OrderLine(); newOrderLine.Book = book; newOrderLine.Quantity = 1; shoppingCart.AddLineItem(newOrderLine); } ViewData.Model = shoppingCart; return RedirectToAction("Index"); }
/// <summary> /// Create a new OrderLine object. /// </summary> /// <param name="bookId">Initial value of the BookId property.</param> /// <param name="orderId">Initial value of the OrderId property.</param> /// <param name="quantity">Initial value of the Quantity property.</param> public static OrderLine CreateOrderLine(global::System.Int32 bookId, global::System.Int32 orderId, global::System.Int32 quantity) { OrderLine orderLine = new OrderLine(); orderLine.BookId = bookId; orderLine.OrderId = orderId; orderLine.Quantity = quantity; return orderLine; }
/// <summary> /// Deprecated Method for adding a new object to the OrderLines EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToOrderLines(OrderLine orderLine) { base.AddObject("OrderLines", orderLine); }
public void AddLineItem(OrderLine lineItem) { orderLines.Add(lineItem); }