Esempio n. 1
0
        public ActionResult Details(long Id)
        {
            selectCategory();
            var displayProduct = new ProductManageDAO().FindByIdCategory(Id);

            return(View(displayProduct));
        }
Esempio n. 2
0
        public ActionResult Create(Product product, HttpPostedFileBase file)
        {
            selectCategory();

            string imageFileName = Path.GetFileName(file.FileName);

            string physicalPath = Path.Combine(Server.MapPath("~/Data"), Path.GetFileName(imageFileName));

            file.SaveAs(physicalPath);


            if (ModelState.IsValid)
            {
                var dao = new ProductManageDAO();
                product.CreateDate = DateTime.Now;
                product.Images     = "/Data/" + file.FileName;
                var result = dao.Insert(product);
                if (result == true)
                {
                    SetAlert("Thêm thành công", "success");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Lỗi không thể thêm bản ghi");
                }
            }

            return(View());
        }
Esempio n. 3
0
        public ActionResult Delete(long Id)
        {
            var dao    = new ProductManageDAO();
            var result = dao.Delete(Id);

            return(RedirectToAction("Index"));
        }
Esempio n. 4
0
        public ActionResult Edit(Product product, HttpPostedFileBase file)
        {
            string imageFileName = Path.GetFileName(file.FileName);

            string physicalPath = Path.Combine(Server.MapPath("~/Data"), Path.GetFileName(imageFileName));

            file.SaveAs(physicalPath);
            if (ModelState.IsValid)
            {
                var dao = new ProductManageDAO();
                product.Images = "/Data/" + file.FileName;
                var result = dao.Edit(product);
                if (result == true)
                {
                    SetAlert("Sửa sản phẩm thành công", "success");
                    return(RedirectToAction("Index"));
                }
            }
            return(View());
        }
Esempio n. 5
0
        public void selectCategory(long?selectedId = null)
        {
            var dao = new ProductManageDAO();

            ViewBag.IDProductCategory = new SelectList(dao.GetListCategory(), "IDProductCategory", "NameProductCategory", selectedId);
        }
Esempio n. 6
0
        // GET: Admin/ProductManage
        public ActionResult Index(string keySearch, int page = 1, int pageSize = 5)
        {
            var model = new ProductManageDAO().GetListAll(keySearch, page, pageSize);

            return(View(model));
        }