コード例 #1
0
        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");
        }
コード例 #2
0
 /// <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;
 }
コード例 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the OrderLines EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrderLines(OrderLine orderLine)
 {
     base.AddObject("OrderLines", orderLine);
 }
コード例 #4
0
 public void AddLineItem(OrderLine lineItem)
 {
     orderLines.Add(lineItem);
 }
コード例 #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the OrderLines EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOrderLines(OrderLine orderLine)
 {
     base.AddObject("OrderLines", orderLine);
 }
コード例 #6
0
 public void AddLineItem(OrderLine lineItem)
 {
     orderLines.Add(lineItem);
 }