Пример #1
0
        public int CreateOrder(Order order)
        {
            int orderTotal = 0;

            var cartItems = GetCartItems();
            foreach (var item in cartItems)
            {
                var orderDetail = new OrderDetail
                {
                    ProductId = item.ProductId,
                    OrderId = order.OrderId,
                    UnitPrice = item.Product.Price,
                    Quantity = item.Count
                };

                orderTotal += (item.Count * item.Product.Price);

                db.OrderDetails.Add(orderDetail);

            }

            order.Total = orderTotal;
            db.SaveChanges();
            EmptyCart();

            return order.OrderId;
        }
 public ActionResult Edit(OrderDetail orderdetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orderdetail).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.ProductId = new SelectList(db.Products, "ProductId", "ProductName", orderdetail.ProductId);
     ViewBag.OrderId = new SelectList(db.Orders, "OrderId", "UserName", orderdetail.OrderId);
     return View(orderdetail);
 }