Beispiel #1
0
 public ActionResult Create(SACH sach)
 {
     if (ModelState.IsValid)
     {
         var  dao = new SanPhamDao();
         long id  = dao.Insert(sach);
         if (id > 0)
         {
             return(RedirectToAction("Index", "SanPham"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm user không thành công");
         }
     }
     return(View("Index"));
 }
        public ActionResult Create(SanPham spham, HttpPostedFileBase HINHANH)
        {
            var  Pathfile = "/FILEs/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/Image/";
            var  filename = Path.GetFileName(HINHANH.FileName);
            bool exsits   = System.IO.Directory.Exists(Server.MapPath(Pathfile));

            if (!exsits)
            {
                System.IO.Directory.CreateDirectory(Server.MapPath(Pathfile));
            }
            var path = Path.Combine(Server.MapPath(Pathfile), filename);

            HINHANH.SaveAs(path);
            spham.Image = Pathfile + filename;
            var  sanphamdao = new SanPhamDao();
            long id         = sanphamdao.Insert(spham);

            ViewBag.ThemTC = "Thêm Thành Công";
            return(RedirectToAction("Create"));
        }