コード例 #1
0
        //[ChildActionOnlyAttribute]
        //public ActionResult RenderOrders(string CartID)
        //{

        //    OrderViewModel objOrderViewModel = new OrderViewModel();
        //   objOrderViewModel.Cart= db.Cart.Include("Products").Where(m => m.cartID == CartID).ToList();
        //   int subtotal= db.Cart.Where(m => m.cartID == CartID).Select(g => g.Price).Sum();
        //   objOrderViewModel.Subtotal = Convert.ToInt16(subtotal);
        //    return PartialView(objOrderViewModel);
        //}

        public ActionResult CheckOrders(string CartID) 
        {
            
            OrderViewModel objOrderViewModel = new OrderViewModel();
            Cart objCart = new Cart();             
            var result = db.Cart.Include("Products").Where(m => m.cartID == CartID ).ToList();
            var CustomerID = db.Orders.Where(m => m.CartID == CartID).FirstOrDefault().CustomerID;
            ViewBag.Customer = db.Customer.Find(CustomerID);
            ViewBag.Total =db.Cart.Where(m => m.cartID == CartID).Select(g => g.Price).Sum();

            return View(result.ToList());
        }
コード例 #2
0
 public ActionResult RenderProducts(string CartID)
 {
     Cart oCart = new Cart();
     var Productslist = db.Cart.Include("Products").Where(m => m.cartID == CartID).ToList();
     return PartialView(Productslist.ToList());
 }
コード例 #3
0
        //public ActionResult InsertCart(int ProductID)
        //{
        //}
        public ActionResult ShowCart(int? ProductID)
        {
            if (User.IsInRole("Admin"))
            {
                RedirectToAction("Index", "Home");
            }
                if (ProductID != null || Session["CartID"] != null)
                {
                    CartViewModel objCarViewModel = new CartViewModel();
                    if (Session["CartID"] == null)
                    {
                        Session.Timeout = 60;
                        EmailService objEmailService = new EmailService();
                        Session["CartID"] = objEmailService.CreateConfirmationToken();
                        int ProdID = Convert.ToInt16(ProductID);
                        int Price = db.Products.Find(ProductID).Price;

                        Cart objCart = new Cart { ProductID = ProdID, Quantity = 1, cartID = Session["CartID"].ToString(), Price = Price };

                        db.Cart.Add(objCart);
                        db.SaveChanges();

                    }
                    else
                    {
                        if (ProductID != null)
                        {
                            if (ProductExist(Convert.ToInt32(ProductID)))
                            {

                            }
                            else
                            {
                                int ProdID = Convert.ToInt16(ProductID);
                                int Price = db.Products.Find(ProductID).Price;
                                Cart objCart = new Cart { ProductID = ProdID, Quantity = 1, cartID = Session["CartID"].ToString(), Price = Price };

                                db.Cart.Add(objCart);
                                db.SaveChanges();
                            }
                        }
                        else
                        {

                        }

                    }
                    if (Session["CartID"] != null)
                    {

                        string CartID = Session["CartID"].ToString();
                        objCarViewModel.Carts = db.Cart.Include("Products").Where(m => m.cartID == CartID).ToList();
                        objCarViewModel.Subtotal = db.Cart.Where(m => m.cartID == CartID).Select(g => g.Price).Sum();

                        foreach (var item in objCarViewModel.Carts)
                        {

                        }

                    }
                    return View(objCarViewModel);
                }
                else
                {
                    ViewBag.Empty = true;
                    return View();

                }
        }