Exemple #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");
        }
Exemple #2
0
        public static string CreateOrder(OrderModel orderModel)
        {
            var order = new Order();
            order.Id = Guid.NewGuid();
            order.Total = orderModel.Total;

            foreach (var orderItemModel in orderModel.OrderItems)
            {
                order.OrderItems.Add(OrderItem.CreateOrderItem(
                    Guid.NewGuid(), orderItemModel.Item.Id, orderItemModel.Quantity, order.Id
                ));
            }

            using (Entities ctx = new Entities())
            {
                var orderType =
                    Convert.ToInt16(ConfigurationManager.AppSettings["ENTITY_ORDER_TYPE"]);
                var orderCounter =
                    ctx.EntityNumberCounters.SingleOrDefault(
                    p => p.EntityType == orderType);

                order.RefNumber = (orderCounter.Counter + 1).ToString();
                ctx.Orders.AddObject(order);

                orderCounter.Counter++;
                ctx.SaveChanges();
            }

            return order.RefNumber;
        }
Exemple #3
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");
        }