public ActionResult EditCategory(ProductCategoryModel model, HttpPostedFileBase file)
        {
            if (model.Id != 0)
            {
                ProductCategoryDao pcDao = new ProductCategoryDao();
                var productCategory = pcDao.GetProductCategoryById(model.Id);
                productCategory.Name = model.Name;
                productCategory.Status = model.Status;
                productCategory.ModifiedDate = DateTime.Now;
                productCategory.ModifiedBy = Constants.Admin;

                if (file != null)
                {
                    string fileName = System.IO.Path.GetFileName(file.FileName);
                    var filePath = "/Content/Images/" + fileName;
                    string path = System.IO.Path.Combine(Server.MapPath("~/Content/Images"), fileName);
                    file.SaveAs(path);
                    model.ImagePath = filePath;
                    productCategory.ImagePath = model.ImagePath;
                }

                pcDao.UpdateProductCategory(productCategory);
            }

            return RedirectToAction("Index");
        }
        // GET: Admin/Product


        #region --- Product category ----
        public ActionResult Index(string keySearch = "")
        {
            //lay du lieu tu DB->Dao->ProductCategoryDao
            ProductCategoryDao pcDao = new ProductCategoryDao();
            //lay tat ca
            var listPC = pcDao.GetAllProductCategories(keySearch);
            //chua co du lieu
            var model = new List<ProductCategoryModel>();

            foreach (var i in listPC)
            {
                var item = new ProductCategoryModel();
                item.Id = i.ID;
                item.Name = i.Name;
                item.CreatedBy = i.CreatedBy;
                item.CreatedDate = i.CreatedDate.HasValue ? i.CreatedDate.Value.ToShortDateString() : "";
                item.ModifiedDate = i.ModifiedDate.HasValue ? i.ModifiedDate.Value.ToShortDateString() : "";
                item.Status = i.Status;
                item.ModifiedBy = i.ModifiedBy;
                item.ImagePath = i.ImagePath;

                model.Add(item);
            }

            return View(model);
        }
        public ActionResult Add()
        {
            ViewBag.Title = "Thêm sản phám ";
            var product         = new ProductDao();
            var productcatogory = new ProductCategoryDao();

            ViewBag.productcatogory = productcatogory.ListCate();

            return(View(product.ListCate()));
        }
Beispiel #4
0
        private IEnumerable <SelectListItem> getCategoriesSelectList(long categoryId)
        {
            ProductCategoryDao pcDao = new ProductCategoryDao();
            var categories           = pcDao.GetAllProductCategories();

            return(categories.Select(x =>
                                     new SelectListItem()
            {
                Text = x.Name,
                Value = x.ID.ToString(),
                Selected = x.ID == categoryId
            }));
        }
        public ActionResult Edit(int id)
        {
            ViewBag.Title = "Sửa sản phẩm";
            var Loaisp   = new ProductCategoryDao();
            var category = new CategoryDao();

            ViewBag.category = category.ListCate();

            var proDao = new ProductDao();

            ViewBag.pro = proDao.getById(id);
            return(View(Loaisp.ListCate()));
        }
        public ActionResult Index()
        {
            ViewBag.Title = "Quản lý Mỹ phẩm";
            var llk = new ProductCategoryDao();
            var lm  = new CategoryDao();

            ViewBag.lm = lm.ListCate();

            ViewBag.llk = llk.ListCate();
            ProductDao dao = new ProductDao();

            return(View(dao.ListProductPage(1, 5)));
        }
Beispiel #7
0
        // GET: Admin/Product
        public ActionResult Index(string keySearch = "")
        {
            ProductDao         productDao = new ProductDao();
            ProductCategoryDao pcDao      = new ProductCategoryDao();
            var listProducts = productDao.GetAll(keySearch);
            var model        = new List <ProductModel>();

            // chuyen doi product qua product model
            foreach (var item in listProducts)
            {
                var modelItem = new ProductModel();
                var category  = pcDao.GetProductCategoryById(item.CategoryID);
                modelItem = mapProductToProductModel(item);
                modelItem.CategoryName = category.Name;
                model.Add(modelItem);
            }
            return(View(model));
        }
Beispiel #8
0
 public ActionResult EditProduct(int id)
 {
     if (id > 0)
     {
         ProductDao         productDao = new ProductDao();
         ProductCategoryDao pcDao      = new ProductCategoryDao();
         var product = productDao.GetProductById(id);
         if (product != null)
         {
             var model      = mapProductToProductModel(product);
             var categories = pcDao.GetAllProductCategories();
             model.Categories = prepareCategories(categories);
             return(View(model));
         }
         return(RedirectToAction("Index"));
     }
     return(RedirectToAction("Index"));
 }
        public ActionResult EditCategory(int id)
        {
            ProductCategoryDao pCDao = new ProductCategoryDao();
            var productCategory = pCDao.GetProductCategoryById(id);
            if (productCategory != null)
            {
                var model = new ProductCategoryModel();

                model.Id = productCategory.ID;
                model.Name = productCategory.Name;
                model.Status = productCategory.Status;
                model.ImagePath = productCategory.ImagePath;

                return View(model);
            }
            else
            {
                return RedirectToAction("Index");
            }
        }