Exemple #1
0
        public ActionResult Edit(int id, SAN_PHAM collection, HttpPostedFileBase fileHinhAnh)
        {
            var SanPhamDAO     = new SanPhamDAO();
            var nhomsanphamDAO = new NhomSanPhamDAO();
            var nhacungcapDAO  = new NhaCungCapDAO();
            var session        = SessionHelper.GetSession();

            //load ds sản phẩm và nhà cung ứng vào drodowbox
            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");

            //xử lý file hình
            string AnhGoc      = SanPhamDAO.GetListProductById(id).HINH_ANH;
            var    imageupload = new ImageUpload(Server.MapPath("~/Content/img"));

            if (imageupload.KiemTraSuaAnh(fileHinhAnh, AnhGoc))
            {
                collection.HINH_ANH = imageupload.FileName;
            }
            else
            {
                ViewBag.ThongBao = "File Ảnh Đã Tồn Tại";
                return(View());
            }



            try
            {
                collection.NGAY_SUA  = DateTime.Today;
                collection.NGUOI_SUA = session.UserName;

                SanPhamDAO.Instance.UpdateProduct(collection);
                if (imageupload.PathFile != null)
                {
                    // fileHinhAnh.SaveAs(imageupload.PathFile);

                    imageupload.SaveResizeImage(Image.FromStream(fileHinhAnh.InputStream), imageupload.PathFile);
                }
                ViewBag.ThongBao = "Sửa Thành Công";
                return(RedirectToAction("Details", new { id = id }));
            }
            catch
            {
                ViewBag.ThongBao = "Sửa Thất Bại";
                return(View());
            }
        }