//public ActionResult Edit(int id) //{ // Product pd = pbo.GetProductbyId(id); // ProductViewModel p = new ProductViewModel() // { // ProductName = pd.ProductName, // CategoryID = pd.CategoryID, // SupplierID = pd.SupplierID, // Quantity = (Int32)pd.Quantity, // UnitPrice = pd.UnitPrice, // ProductImage = pd.ProductImage, // Description = pd.Description, // }; // ViewBag.Cat = new SelectList(catbo.GetAllCat(), "CategoryID", "CategoryName"); // return View(p);//trả về View Edit kèm biến Model là RecipeViewModel //} //[HttpPost] //public ActionResult Edit(ProductViewModel model) //{ // if (ModelState.IsValid) // { // Product p = new Product() // { // ProductID = model.ProductID, // ProductName = model.ProductName, // CategoryID = model.CategoryID, // SupplierID = model.SupplierID, // Quantity = (Int32)model.Quantity, // UnitPrice = model.UnitPrice, // ProductImage = model.ProductImage, // Description = model.Description // }; // pbo.EditProduct(p); // return RedirectToAction("Index"); // } // ModelState.AddModelError("", "Error input!"); // ViewBag.Cat = new SelectList(catbo.GetAllCat(), "CategoryID", "CategoryName"); // return View(model); //} public ActionResult Edit(int id) { Product pd = pbo.GetProductbyId(id); ProductViewModel p = new ProductViewModel() { ProductName = pd.ProductName, CategoryID = pd.CategoryID, SupplierID = pd.SupplierID, Quantity = (Int32)pd.Quantity, UnitPrice = pd.UnitPrice, Description = pd.Description, }; ViewBag.Cat = new SelectList(catbo.GetAllCat(), "CategoryID", "CategoryName"); return(View(p));//trả về View Edit kèm biến Model là RecipeViewModel }
public ProductCard(int proId) { pbo = new ProductBO(); iProID = proId; Product p = pbo.GetProductbyId(proId); sProName = p.ProductName; dPrice = (decimal)p.UnitPrice; iQuantity = 1; }
}//action xem gio hang //Cập nhật giỏ hàng public ActionResult UpdateCart(int ProId, FormCollection f) { //Kiểm tra sp Product p = pbo.GetProductbyId(ProId); if (p == null) { Response.StatusCode = 404; return(null); } //Lấy giỏ hàng ra từ session List <ProductCard> lstCart = GetCard(); ProductCard c = lstCart.FirstOrDefault(n => n.iProID == ProId); //Nếu có sp trong giỏ hàng if (c != null) { c.iQuantity = int.Parse(f["txtSoLuong"].ToString()); } return(RedirectToAction("ViewShoppingCard")); }