public ActionResult Create(SAN_PHAM sanpham, HttpPostedFileBase fileHinhAnh) { //load ds sản phẩm và nhà cung ứng vào drodowbox var nhomsanphamDAO = new NhomSanPhamDAO(); var nhacungcapDAO = new NhaCungCapDAO(); ViewBag.MA_NHOM_SP = new SelectList(nhomsanphamDAO.GetCatalogueAll(), "MA_NHOM_SP", "TEN_NHOM_SP"); ViewBag.MA_NCC = new SelectList(nhacungcapDAO.GetListSupplier(), "MA_NCC", "TEN_NCC"); //kiểm tra ảnh var imageupload = new ImageUpload(Server.MapPath("~/Content/img")); if (imageupload.KiemTraThemAnhMoi(fileHinhAnh)) { sanpham.HINH_ANH = imageupload.FileName; } else { ViewBag.ThongBao = "File Ảnh Đã Tồn Tại"; return(View()); } try { int idnewproduct = SanPhamDAO.Instance.InsertProduct(sanpham); // fileHinhAnh.SaveAs(imageupload.PathFile); imageupload.SaveResizeImage(Image.FromStream(fileHinhAnh.InputStream), imageupload.PathFile); return(RedirectToAction("Details", new { id = idnewproduct })); } catch { ViewBag.ThongBao = "Thêm Thất Bại"; return(View()); } }