public bool edit(CayThuoc caythuoc) { try { ModelDbContext db = new ModelDbContext(); var old_data = db.CayThuocs.Find(caythuoc.ID); if (caythuoc.TenCayThuoc.Length > 0) { old_data.TenCayThuoc = caythuoc.TenCayThuoc; } old_data.AnhMinhHoa = caythuoc.AnhMinhHoa; old_data.CongDung = caythuoc.CongDung; old_data.ChiTiet = caythuoc.ChiTiet; old_data.GhiChu = caythuoc.GhiChu; old_data.TrangThai = caythuoc.TrangThai; db.SaveChanges(); return(true); } catch { return(false); } }
public ActionResult Create(CayThuoc caythuoc) //FormCollection collection { DbCayThuoc db = new DbCayThuoc(); //if (new System.IO.FileInfo("AnhMinhHoa").Length != 0) try { HttpPostedFileBase File = Request.Files["AnhMinhHoa"]; string path = Server.MapPath("~/images/" + File.FileName); string img_url = "images/" + File.FileName; File.SaveAs(path); caythuoc.AnhMinhHoa = img_url; if (db.add(caythuoc)) { return(RedirectToAction("Index")); } else { ViewBag.Caythuoc_add_message = "Không thể thêm dữ liệu 10"; return(View()); } } catch { ViewBag.Caythuoc_add_message = "Không thể thêm dữ liệu"; return(View()); } }
public bool add(CayThuoc caythuoc) { try { ModelDbContext db = new ModelDbContext(); db.CayThuocs.Add(caythuoc); db.SaveChanges(); return(true); } catch { return(false); } }
public ActionResult Edit(CayThuoc caythuoc) { DbCayThuoc db = new DbCayThuoc(); var old_data = db.detail(caythuoc.ID); //if (new System.IO.FileInfo("AnhMinhHoa").Length != 0) try { if (Request.Files["AnhMinhHoa"] != null) { HttpPostedFileBase File = Request.Files["AnhMinhHoa"]; string path = Server.MapPath("~/images/" + File.FileName); string img_url = "images/" + File.FileName; File.SaveAs(path); caythuoc.AnhMinhHoa = img_url; } else { caythuoc.AnhMinhHoa = old_data.AnhMinhHoa; } if (db.edit(caythuoc)) { return(RedirectToAction("Index")); } else { ViewBag.Caythuoc_add_message = "Không thể sửa dữ liệu 10"; return(View()); } } catch { ViewBag.Caythuoc_add_message = "Không thể sửa dữ liệu"; return(View()); } }