public bool SaveChiTietTKB(int maTKB, int thu, int tiet, int maMH, int maGV, int maPhong) { try { using (var db = new TKBEntities()) { ChiTietTKB chiTiet = new ChiTietTKB() { ThoiKhoaBieu = db.ThoiKhoaBieux.FirstOrDefault(p => p.MaTKB == maTKB), MonHoc = db.MonHocs.FirstOrDefault(p => p.MaMonHoc == maMH), GiaoVien = db.GiaoViens.FirstOrDefault(p => p.MaGiaoVien == maGV), Phong = db.Phongs.FirstOrDefault(p => p.MaPhong == maPhong), TietBatDau = tiet, TietKetThuc = tiet, Thu = thu }; db.AddToChiTietTKBs(chiTiet); db.SaveChanges(); } return true; } catch (Exception ex) { return false; } }
private void SaveTKB(List<ThoiKhoaBieu> lstTKB, List<Lop> dsLop) { using (var db = new TKBEntities()) { foreach (ThoiKhoaBieu oTKB in lstTKB) { if (oTKB.MaTKB == 0) { ThoiKhoaBieu tkb = new ThoiKhoaBieu() { Lop = db.Lops.FirstOrDefault(p => p.MaLop == oTKB.Lop.MaLop), NamHoc = oTKB.NamHoc }; db.AddToThoiKhoaBieux(tkb); db.SaveChanges(); foreach (ChiTietTKB ct in oTKB.ChiTietTKBs.ToList()) { ChiTietTKB chiTiet = new ChiTietTKB() { ThoiKhoaBieu = tkb, MonHoc = db.MonHocs.FirstOrDefault(p => p.MaMonHoc == ct.MonHoc.MaMonHoc), GiaoVien = db.GiaoViens.FirstOrDefault(p => p.MaGiaoVien == ct.GiaoVien.MaGiaoVien), Phong = db.Phongs.FirstOrDefault(p => p.MaPhong == ct.Phong.MaPhong), TietBatDau = ct.TietBatDau + 1, TietKetThuc = ct.TietKetThuc + 1, Thu = ct.Thu + 2 }; db.AddToChiTietTKBs(chiTiet); db.SaveChanges(); } } } } }