Exemple #1
0
        public JsonResult AddToCart()
        {
            JsonResult res = new JsonResult();
            JsonMessage message = new JsonMessage();
            res.Data = message;
            int pdtId = 0;

            int.TryParse(Request["product_id"],out pdtId);
            ShopManager manager = new ShopManager(null);
            Product pdt = manager.GetProduct(pdtId);
            if (pdt != null)
            {
                pdt.Quantity = 1;
            }
            List<Product> products = new List<Product>();

            if (Session["cart"] == null)
            {
                Session["cart"] = products;
            }
            else
            {
                products = (List<Product>)Session["cart"];
            }

            Product existed = (from p in products where p.ID == pdtId select p).FirstOrDefault<Product>();
            if (existed == null)
            {
                products.Add(pdt);
            }
            else
            {
                existed.Quantity += 1;
            }

            message.Status = "ok";
            return res;
        }
Exemple #2
0
        public JsonResult RemoveFromCart()
        {
            JsonResult res = new JsonResult();
            JsonMessage message = new JsonMessage();
            res.Data = message;
            int pdtId = 0;

            int.TryParse(Request["product_id"], out pdtId);
            ShopManager manager = new ShopManager(null);
            Product pdt = manager.GetProduct(pdtId);

            List<Product> products = new List<Product>();

            if (Session["cart"] != null)
            {
                products = (List<Product>)Session["cart"];
            }

            Product existed = (from p in products where p.ID == pdtId select p).FirstOrDefault<Product>();

            if (existed != null)
            {
                products.Remove(existed);
            }
            message.Status = "ok";

            return res;
        }
Exemple #3
0
        public ActionResult EditProduct(int id)
        {
            User user = (User)Session["User"];
            ShopManager shopMgr = new ShopManager(user);
            List<Category> cates = shopMgr.GetCategories();
            List<Category> ccates = null;
            Product product = shopMgr.GetProduct(id);
            List<Image> images = shopMgr.GetProductImages(id);
            Category category = (from c in cates where c.ID == product.CategoryID select c).FirstOrDefault<Category>();

            int pcid = 0;
            if (category.ParentID > 0)
            {
                pcid = (int)category.ParentID;
                ccates = (from c in cates where c.ParentID == category.ParentID select c).ToList<Category>();
            }

            cates = (from c in cates where c.ParentID == 0 select c).ToList<Category>();
            ViewData["cate"] = cates;
            ViewData["ccate"] = ccates;
            ViewData["images"] = images;
            ViewBag.pcid = pcid;
            return View(product);
        }