public ActionResult TaoLich(LichNop lichNop) { if (ModelState.IsValid) { try { string[] ds = (string[])Session["dsgv"]; var session = (TaiKhoan)Session[ComMon.ComMonStants.UserLogin]; if (ds.Length > 1) { lichNop.TrangThai = true; lichNop.xoa = true; lichNop.MaBoMON = session.TaiKhoan1; TracNghiemOnlineDB db = new TracNghiemOnlineDB(); db.LichNops.Add(lichNop); db.SaveChanges(); for (int i = 0; i < ds.Length - 1; i++) { DSGV_ThucHien GV = new DSGV_ThucHien(); GV.MaGV = ds[i]; GV.MaLich = new TracNghiemOnlineDB().LichNops.ToList().Last().id; db.DSGV_ThucHien.Add(GV); db.SaveChanges(); } return(RedirectToAction("BoMON")); } } catch { ModelState.AddModelError("", "Vui lòng chọn giáo viên "); } } return(View(lichNop)); }
public ActionResult Updatebomon(LichNop lichNop) { if (ModelState.IsValid) { try { string[] ds = (string[])Session["dsgv"]; var session = (TaiKhoan)Session[ComMon.ComMonStants.UserLogin]; if (ds.Length > 1) { TracNghiemOnlineDB db = new TracNghiemOnlineDB(); var lich = db.LichNops.Find(lichNop.id); lich.NoiDung = lichNop.NoiDung; lich.ThoiGian = lichNop.ThoiGian; lich.MaMon = lichNop.MaMon; db.SaveChanges(); var list = db.DSGV_ThucHien.Where(x => x.MaLich == lichNop.id).ToList(); foreach (var item in list) { db.DSGV_ThucHien.Remove(item); db.SaveChanges(); } for (int i = 0; i < ds.Length - 1; i++) { DSGV_ThucHien GV = new DSGV_ThucHien(); GV.MaGV = ds[i]; GV.MaLich = lichNop.id; db.DSGV_ThucHien.Add(GV); db.SaveChanges(); } return(RedirectToAction("BoMON")); } } catch { ModelState.AddModelError("", "Vui lòng chọn giáo viên "); } } return(View(lichNop)); }