Example #1
0
        public ActionResult CapNhat(SanPhamViewModel _sanPham)
        {
            bool result = sanPham.CapNhat(_sanPham);

            return(RedirectToAction("Index"));
        }
Example #2
0
        public ActionResult ChinhSua(int id, SanPham sp, HttpPostedFileBase[] HinhAnh)
        {
            ViewBag.MaNCC = new SelectList(_nccService.LayTatCa(), "MaNCC", "Ten");
            ViewBag.MaLSP = new SelectList(_lspService.LayTatCa(), "MaLSP", "Ten");
            ViewBag.MaNSX = new SelectList(_nsxService.LayTatCa(), "MaNSX", "Ten");
            SanPham tp = _spService.LayTheoMa(id);

            var fileName  = "";
            var fileName1 = "";
            var fileName2 = "";
            var fileName3 = "";

            if (HinhAnh[0] != null)
            {
                if (HinhAnh[0].ContentLength > 0)
                {
                    fileName = UploadHelper.RenameImage(Path.GetExtension(HinhAnh[0].FileName));
                    var path = Path.Combine(Server.MapPath("~/Assets/images/SanPham"), fileName);
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                    HinhAnh[0].SaveAs(path);
                }
            }

            if (HinhAnh[1] != null)
            {
                if (HinhAnh[1].ContentLength > 0)
                {
                    fileName = UploadHelper.RenameImage(Path.GetExtension(HinhAnh[1].FileName));
                    var path = Path.Combine(Server.MapPath("~/Assets/images/SanPham"), fileName);
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                    HinhAnh[1].SaveAs(path);
                }
            }

            if (HinhAnh[2] != null)
            {
                if (HinhAnh[2].ContentLength > 0)
                {
                    fileName = UploadHelper.RenameImage(Path.GetExtension(HinhAnh[2].FileName));
                    var path = Path.Combine(Server.MapPath("~/Assets/images/SanPham"), fileName);
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                    HinhAnh[2].SaveAs(path);
                }
            }

            if (HinhAnh[3] != null)
            {
                if (HinhAnh[3].ContentLength > 0)
                {
                    fileName = UploadHelper.RenameImage(Path.GetExtension(HinhAnh[3].FileName));
                    var path = Path.Combine(Server.MapPath("~/Assets/images/SanPham"), fileName);
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                    HinhAnh[3].SaveAs(path);
                }
            }

            if (HinhAnh[0] != null)
            {
                sp.HinhAnh = fileName;
            }
            else
            {
                sp.HinhAnh = tp.HinhAnh;
            }
            if (HinhAnh[1] != null)
            {
                sp.HinhAnh1 = fileName1;
            }
            else
            {
                sp.HinhAnh1 = tp.HinhAnh1;
            }
            if (HinhAnh[2] != null)
            {
                sp.HinhAnh2 = fileName2;
            }
            else
            {
                sp.HinhAnh2 = tp.HinhAnh2;
            }
            if (HinhAnh[3] != null)
            {
                sp.HinhAnh3 = fileName3;
            }
            else
            {
                sp.HinhAnh3 = tp.HinhAnh3;
            }
            sp.NgayCapNhat = DateTime.Now;
            _spService.CapNhat(sp);
            _spService.luu();
            TempData["Message"] = "Cập nhật thành công!";
            return(RedirectToAction("Index"));
        }