public void SetViewBag(long?seletedID = null)
        {
            var dao = new Model.Dao.ProductDao();

            ViewBag.Category_ID = new SelectList(dao.ListAllCategory(), "ID", "Name", seletedID);
            ViewBag.Brand_ID    = new SelectList(dao.ListAllBrand(), "ID", "Name", seletedID);
        }
 public ActionResult Detail(long id)
 {
     var product = new ProductDao().ViewDetail(id);
     ViewBag.Category = new ProductCategoryDao().ViewDetail(product.CategoryID.Value);
     ViewBag.RelatedProduct = new ProductDao().ListRelatedProduct(id);
     return View(product);
 }
Exemple #3
0
 // GET: Home
 public ActionResult Index()
 {
     ViewBag.Slides = new SlideDao().ListAll();
     var productDao = new ProductDao();
     ViewBag.NewProducts = productDao.ListNewProduct(4);
     ViewBag.ListFeatureProducts = productDao.ListFeatureProduct(4);
     return View();
 }
 public JsonResult ListName(string q)
 {
     var data = new ProductDao().ListName(q);
     return Json(new
     {
         data = data,
         status = true
     },JsonRequestBehavior.AllowGet);
 }
        public ActionResult AddItem(long productId, int quantity)
        {
            var product = new ProductDao().ViewDetail(productId);
            var cart = Session[CartSession];
            if (cart != null)
            {
                var list = (List<CartItem>)cart;

                if (list.Exists(x => x.Product.ID == productId))
                {
                    foreach (var item in list)
                    {
                        if (item.Product.ID == productId)
                        {
                            item.Quantity += quantity;
                        }
                    }
                }
                else
                {
                    //Tạo mới đối tượng
                    var item = new CartItem();
                    item.Product = product;
                    item.Quantity = quantity;
                    list.Add(item);
                }
                //Gán vào session
                Session[CartSession] = list;
            }
            else
            {
                //Tạo mới đối tượng
                var item = new CartItem();
                item.Product = product;
                item.Quantity = quantity;
                var list = new List<CartItem>();
                list.Add(item);

                //Gán vào session
                Session[CartSession] = list;
            }
            return RedirectToAction("Index");
        }
        public ActionResult Search(string keyword, int page = 1, int pageSize = 1)
        {
            int totalRecord = 0;
            var model = new ProductDao().Search(keyword, ref totalRecord, page, pageSize);

            ViewBag.Total = totalRecord;
            ViewBag.Page = page;
            ViewBag.Keyword = keyword;
            int maxPage = 5;
            int totalPage = 0;

            totalPage = (int)Math.Ceiling((double)(totalRecord / pageSize));
            ViewBag.TotalPage = totalPage;
            ViewBag.MaxPage = maxPage;
            ViewBag.First = 1;
            ViewBag.Last = totalPage;
            ViewBag.Next = page + 1;
            ViewBag.Prev = page - 1;

            return View(model);
        }
        public ActionResult Category(long cateId,int page=1, int pageSize=1)
        {
            var category = new CategoryDao().ViewDetail(cateId);
            ViewBag.Category = category;
            int totalRecord = 0;
            var model = new ProductDao().ListByCategoryId(cateId,ref totalRecord, page, pageSize);

            ViewBag.Total = totalRecord;
            ViewBag.Page = page;

            int maxPage = 5;
            int totalPage = 0;

            totalPage = (int)Math.Ceiling((double)(totalRecord/pageSize));
            ViewBag.TotalPage = totalPage;
            ViewBag.MaxPage = maxPage;
            ViewBag.First = 1;
            ViewBag.Last = totalPage;
            ViewBag.Next = page + 1;
            ViewBag.Prev = page - 1;

            return View(model);
        }
 // GET: Admin/Product
 public ActionResult Index()
 {
     var dao = new ProductDao();
     var model = dao.ListProduct();
     return View(model);
 }