private void DeleteTKB(int maLop, string namHoc) { using (var db = new TKBEntities()) { ThoiKhoaBieu tkb = db.ThoiKhoaBieux.FirstOrDefault(p => p.Lop.MaLop == maLop && (p.NamHoc == namHoc || (namHoc == null && p.NamHoc.Equals(null)))); if (tkb != null) { List<ChiTietTKB> chiTiets = db.ChiTietTKBs.Where(p => p.ThoiKhoaBieu.MaTKB == tkb.MaTKB).ToList(); if (chiTiets != null) { foreach (var ct in chiTiets) { db.DeleteObject(ct); } db.SaveChanges(); } db.DeleteObject(tkb); db.SaveChanges(); } } }
public bool XoaPhong(int maPhong) { try { using (var db = new TKBEntities()) { Phong gv = db.Phongs.First(l => l.MaPhong == maPhong); db.DeleteObject(gv); db.SaveChanges(); return true; } } catch { return false; } }
public bool XoaGiaoVien(int maGiaoVien) { try { using (var db = new TKBEntities()) { GiaoVien gv = db.GiaoViens.First(l => l.MaGiaoVien == maGiaoVien); db.DeleteObject(gv); db.SaveChanges(); return true; } } catch { return false; } }
public bool XoaLop(int maLop) { try { using (var db = new TKBEntities()) { Lop lop = db.Lops.First(l => l.MaLop == maLop); db.DeleteObject(lop); db.SaveChanges(); return true; } } catch { return false; } }
public bool DeleteChiTietTKB(int maChiTiet) { try { using (var db = new TKBEntities()) { ChiTietTKB chiTiet = db.ChiTietTKBs.FirstOrDefault(p => p.MaChiTietTKB == maChiTiet); if (chiTiet != null) { db.DeleteObject(chiTiet); db.SaveChanges(); } return true; } } catch (Exception ex) { return false; } }