Esempio n. 1
0
        public ActionResult CheckoutScreen(Order order)
        {
            if (ModelState.IsValid)
            {
                int? orderIndex = null;

                order.TotalPrice = 0.0M;

                musicStoreContext.Orders.Add(order);

                List<OrderItem> items = new List<OrderItem>();

                order.OrderItemsList = new List<OrderItem>();

                foreach (var item in GetCart().Products)
                {
                    order.OrderItemsList.Add(new OrderItem() { ProductId = item.Product.ProductId, Quantity = item.Quantity });
                }

                order.TotalPrice = GetCart().Products.Sum(item => item.Quantity * item.Product.Price);
                musicStoreContext.SaveChanges();
                orderIndex = order.OrderId;
                ViewBag.OrderIndex = orderIndex;

                Session["Cart"] = new ShoppingCart();

                return View("OrderInfo");
            }

            return View(order);
        }
Esempio n. 2
0
 ShoppingCart GetCart()
 {
     var cart = (ShoppingCart)Session["Cart"];
     if (cart == null)
     {
         cart = new ShoppingCart();
         Session["Cart"] = cart;
     }
     return cart;
 }