コード例 #1
0
        public ActionResult Newproduct()
        {
            PRODUCTdao           dao = new PRODUCTdao();
            IQueryable <Product> pro = dao.Newproduct();

            return(View(pro));
        }
コード例 #2
0
        public ActionResult AddToCart(long productId, int quantity)
        {
            var product = new PRODUCTdao().producrDetail(productId);
            var cart    = Session[CartSession];

            //nếu cart đã tồn tại
            if (cart != null)
            {
                //ép lại giở hàng đã tồn tại thành list
                var list = (List <CartItem>)cart;
                if (list.Exists(x => x.ProductModel.ID == productId))
                {
                    foreach (var item in list)
                    {
                        //nếu sản phẩm trùng tăng số lượng sản phẩm đó lên
                        if (item.ProductModel.ID == productId)
                        {
                            item.Quantity += quantity;
                        }
                    }
                }//nếu không chứa add mới
                else
                {
                    //thêm mối một giỏ hàng
                    var item = new CartItem();
                    item.ProductModel = product;
                    item.Quantity     = quantity;
                    list.Add(item);
                }
                //gán danh sách vào session
                Session[CartSession] = list;
            }
            else//chưa tồn tại
            {
                //thêm mối một giỏ hàng
                var item = new CartItem();
                item.ProductModel = product;
                item.Quantity     = quantity;
                var list = new List <CartItem>();
                list.Add(item);
                //gán danh sách vào session
                Session[CartSession] = list;
            }
            return(RedirectToAction("Cart"));
        }
コード例 #3
0
        public ActionResult Test(int?idProducer, int?idCate, string SearchTerm)
        {
            PRODUCTdao     dao = new PRODUCTdao();
            List <Product> pro = dao.LoaiHangSp(idCate, idProducer).ToList();

            ViewBag.SearchTerm = SearchTerm;
            var ls = model.Product.Where(x => x.Name.Contains(SearchTerm)).ToList();

            if ((idProducer == null) && (idCate == null))
            {
                return(View(ls));
            }
            else
            {
                return(View(pro));
            }
            //var ls = model.PRODUCTs.Where(x => x.ID_PRODUCER == idProducer && x.ID_CATEGORY == idCate).ToList();
            //return View(ls);
        }