Beispiel #1
0
        public ActionResult COnfirmOrder()
        {
            var UserName = User.Identity.GetUserName();

            ViewBag.Total    = cart_Service.GetCartTotal(cart_Service.GetCartID());
            ViewBag.TotalQTY = cart_Service.GetCartItems().FindAll(x => x.cart_id == cart_Service.GetCartID()).Sum(q => q.quantity);
            var confirm = db.FoodOrders.ToList();
            var cart    = db.Cart_Items.ToList();

            MealOrder mealOrder = new MealOrder();

            mealOrder.OrderNumber = mealOrder.GenVoucher();
            mealOrder.Total       = ViewBag.Total;
            mealOrder.UserOrder   = UserName;
            mealOrder.Status      = "Paid";
            mealOrder.OrderDate   = DateTime.Now.Date.ToLongDateString();
            db.MealOrders.Add(mealOrder);
            db.SaveChanges();

            FoodOrder foodOrder = new FoodOrder();

            foreach (var item in confirm)
            {
                foreach (var i in cart)
                {
                    if (UserName == item.UserEmail && item.cart_id == i.cart_id)
                    {
                        var statusUpdate = db.FoodOrders.Find(item.cart_item_id);
                        statusUpdate.OrderStatus     = "Checked Out";
                        statusUpdate.OrderId         = mealOrder.OrderId;
                        db.Entry(statusUpdate).State = EntityState.Modified;
                        db.SaveChanges();
                        cart_Service.EmptyCart();
                    }
                }
            }

            return(RedirectToAction("OnceOff", new { tot = mealOrder.Total }));
        }
Beispiel #2
0
 public ActionResult ShoppingCart()
 {
     ViewBag.Total    = cart_Service.GetCartTotal(cart_Service.GetCartID());
     ViewBag.TotalQTY = cart_Service.GetCartItems().FindAll(x => x.cart_id == cart_Service.GetCartID()).Sum(q => q.quantity);
     return(View(cart_Service.GetCartItems().FindAll(x => x.cart_id == cart_Service.GetCartID())));
 }