Beispiel #1
0
        public ActionResult Create(OrderModel order)
        {
            if (Session["Cart"] != null)
            {
                var orderFromCart = new OrderModel();

                var cart = (CartModel)Session["Cart"];
                foreach (var cartLineItem in cart.GetLineItems())
                {
                    var orderItem = new OrderItemModel
                    {
                        Item = cartLineItem.Item,
                        Quantity = cartLineItem.Quantity,
                    };

                    orderFromCart.OrderItems.Add(orderItem);
                }

                var refNumber = OrderManager.CreateOrder(orderFromCart);
                cart.Empty();

                ViewBag.OrderNumber = refNumber;

                return RedirectToAction("Successful", new { refNumber = refNumber });
            }

            return RedirectToAction("Index", "Home");
        }
Beispiel #2
0
        public ActionResult Create()
        {
            if (Session["Cart"] != null)
            {
                var order = new OrderModel();

                var cart = (CartModel)Session["Cart"];
                foreach (var cartLineItem in cart.GetLineItems())
                {
                    var orderItem = new OrderItemModel
                    {
                        Item = cartLineItem.Item,
                        Quantity = cartLineItem.Quantity,
                    };

                    order.OrderItems.Add(orderItem);
                }

                return View(order);
            }

            return RedirectToAction("Index", "Home");
        }
Beispiel #3
0
        public void AddLineItem(ProductModel productModel)
        {
            bool found = false;
            foreach (var item in GetLineItems())
            {
                if (item.Item.Id == productModel.Id)
                {
                    item.Quantity++;
                    found = true;

                    break;
                }
            }

            if (!found)
            {
                var newLineItem = new OrderItemModel
                {
                    Item = productModel,
                    Quantity = 1,
                };
                _LineItems.Add(newLineItem);
            }
        }