// GET: Baithuoc/Details/5 public ActionResult Details(int id) { DBBaithuoc db = new DBBaithuoc(); var data = db.detail(id); // DbCaythuocBaithuoc cay_bai = new DbCaythuocBaithuoc(); DbCayThuoc caythuoc_db = new DbCayThuoc(); var lis_cay = cay_bai.cay_thuoc_theo_bai_thuoc(id); List <int> id_cay = new List <int>(); foreach (var cay in lis_cay) { id_cay.Add(cay.ID_CayThuoc); } List <string> ten_cay = new List <string>(); foreach (var id_cay_thuoc in id_cay) { var cay_thuoc = caythuoc_db.detail(id_cay_thuoc); ten_cay.Add(cay_thuoc.TenCayThuoc); } ViewBag.DsTenCay = ten_cay; // ViewBag.List_Cay = lis_cay; return(View(data)); }
public ActionResult Delete(int id, FormCollection collection) { DBBaithuoc db = new DBBaithuoc(); var data = db.detail(id); try { // TODO: Add delete logic here if (db.delete(id)) { return(RedirectToAction("Index")); } else { ViewBag.Delete_Message = "Không thể xóa dữ liệu"; return(View(data)); } } catch { ViewBag.Delete_Message = "Không thể xóa dữ liệu"; return(View(data)); } }
public ActionResult Edit(BaiThuoc baithuoc, int[] DanhSachCayThuoc) { danh_sach_cay_thuoc(); DbCaythuocBaithuoc cay_bai = new DbCaythuocBaithuoc(); DBBaithuoc bt = new DBBaithuoc(); ViewBag.Selected_caythuoc = cay_bai.cay_thuoc_theo_bai_thuoc(baithuoc.ID); var old_data = bt.detail(baithuoc.ID); try { // TODO: Add update logic here HttpPostedFileBase File = Request.Files["AnhMinhHoa"]; if (Request.Files["AnhMinhHoa"] != null) { string path = Server.MapPath("~/images/" + File.FileName); string img_url = "images/" + File.FileName; File.SaveAs(path); baithuoc.AnhMinhHoa = img_url; } else { baithuoc.AnhMinhHoa = old_data.AnhMinhHoa; } DBBaithuoc db = new DBBaithuoc(); DbCaythuocBaithuoc caythuoc_baithuoc = new DbCaythuocBaithuoc(); if (db.edit(baithuoc)) { caythuoc_baithuoc.delete(baithuoc.ID); foreach (int item in DanhSachCayThuoc) { caythuoc_baithuoc.addnew(item, baithuoc.ID); } return(RedirectToAction("Index")); } else { return(View(baithuoc)); } } catch { return(View(baithuoc)); } }
// GET: Baithuoc/Delete/5 public ActionResult Delete(int id) { DBBaithuoc db = new DBBaithuoc(); var data = db.detail(id); if (data != null) { return(View(data)); } else { return(RedirectToAction("Index")); } }
// GET: Baithuoc/Edit/5 public ActionResult Edit(int id) { danh_sach_cay_thuoc(); DBBaithuoc db = new DBBaithuoc(); DbCaythuocBaithuoc cay_bai = new DbCaythuocBaithuoc(); var data = db.detail(id); ViewBag.Selected_caythuoc = cay_bai.cay_thuoc_theo_bai_thuoc(id); if (data != null) { return(View(data)); } else { return(RedirectToAction("Index")); } }