/// <summary>
        /// 靜態方法,用來實例ShoppingCartLogic
        /// </summary>
        /// <param name="inContext">目前Context</param>
        /// <returns></returns>
        public static ShoppingCartLogic GetShoppingCart(HttpContextBase inContext)
        {
            ShoppingCartLogic cart = new ShoppingCartLogic();

            cart.UserId = cart.GetUserId(inContext);
            return(cart);
        }
        public ActionResult DeleteConfirmed(int shoppingCartId)
        {
            shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);

            shoppingCartLogic.RemoveFromCart(shoppingCartId);

            shoppingCartLogic.SaveChanges();
            return RedirectToAction("Index");
        }
        /// <summary>
        /// 把一個餐加入到購物車
        /// </summary>
        /// <param name="mealId"></param>
        /// <returns></returns>
        public ActionResult AddToCart(int mealId)
        {
            shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);

            shoppingCartLogic.AddToCart(mealId);
            shoppingCartLogic.SaveChanges();

            return RedirectToAction("Index");
        }
        public ActionResult Delete(int shoppingCartId = 0)
        {
            shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);
            ShoppingCart shoppingcart = shoppingCartLogic.GetShoppingCartUsingShoppingCartId(shoppingCartId);

            if (shoppingcart == null)
            {
                return HttpNotFound();
            }
            return View(shoppingcart);
        }
 /// <summary>
 /// 靜態方法,用來實例ShoppingCartLogic
 /// </summary>
 /// <param name="inContext">目前Context</param>
 /// <returns></returns>
 public static ShoppingCartLogic GetShoppingCart(HttpContextBase inContext)
 {
     ShoppingCartLogic cart = new ShoppingCartLogic();
     cart.UserId = cart.GetUserId(inContext);
     return cart;
 }
        public ActionResult ProcedToCheckout(CreateOrderViewModel viewModel)
        {
            var customer = orderRepo.GetSingleEntity(x => x.UserId == User.Identity.Name);

            if (ModelState.IsValid)
            {
                Order order = ConvertViewModelToOrder(viewModel, User.Identity.Name);

                orderRepo.Insert(order);
                orderRepo.SaveChanges();

                shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);
               order.TotalPrice = shoppingCartLogic.ShoppingCartToOrderDetails(order);

               orderRepo.Update(order);
               orderRepo.SaveChanges();

                return RedirectToAction("Index");
            }

            viewModel.PaymentMethods = paymentMethodRepo.GetWithFilterAndOrder();
            viewModel.CollectionMethods = collectionRepo.GetWithFilterAndOrder();

            return View(viewModel);
        }
        public ActionResult EmptyShoppingCart(string userId)
        {
            //TODO: Make it ajax. All shopping cart can be wrap up into a partial view
            shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);

            shoppingCartLogic.EmptyCart();
            return RedirectToAction("Index");
        }
        public PartialViewResult ShoppingCartCount()
        {
            shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);

            return PartialView("_ShoppingCartCount", shoppingCartLogic.GetShoppingCartCount());
        }
        //
        // GET: /ShoppingCart/
        public ActionResult Index()
        {
            shoppingCartLogic = ShoppingCartLogic.GetShoppingCart(this.HttpContext);

            var viewModel = new ViewModels.ShoppingCartViewModel ();

            viewModel.CartItems = shoppingCartLogic.GetShoppingCartItems().ToList();
               viewModel.TotalPrice = shoppingCartLogic.GetShoppingCartTotalPrice(viewModel.CartItems);

               ViewBag.ShowEdit = true;
               ViewBag.Title = "購物車內容";

            return View(viewModel);
        }