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 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)); }
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"); } }