Example #1
0
        public int CreateOrder(Order order)
        {
            decimal orderTotal = 0; //Price of entire order

            var cartItems = GetCartItems();

            foreach (var item in cartItems)
            {
                var hatOrder = new HatOrder
                {
                    HatId = item.HatId,
                    OrderId = order.Id,
                    Quantity = item.Count,
                    Subtotal = item.Hat.Price * item.Count
                };
                orderTotal += (hatOrder.Subtotal);

                db.HatOrders.Add(hatOrder);
            }
            order.TotalCost = orderTotal;
            order.Status = "Waiting";

            db.SaveChanges();
            EmptyCart();

            return order.Id; //return confirmation number of Order
        }
Example #2
0
        public ActionResult Checkout(FormCollection values)
        {
            var order = new Order();

            UserManager<ApplicationUser> userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
            decimal total = decimal.Parse(Session["Total"].ToString());

            order.User = userManager.FindByName(User.Identity.Name);
            order.TotalCost = total;
            order.Status = "Waiting";

                db.Orders.Add(order);
                db.SaveChanges();

                var cart = ShoppingCart.GetCart(this.HttpContext);
                cart.CreateOrder(order);

                return RedirectToAction("Complete", new { id = order.Id });
        }