public int ImportListTraining(List <ImportTraining> listImport) { //Check timeout import int result = 0; foreach (var item in listImport) { Vlu_MonHoc objMH = ObjectContext.Vlu_MonHoc.FirstOrDefault(c => c.MonHocID == item.MonHocID); Vlu_Khoa objKhoa = ObjectContext.Vlu_Khoa.FirstOrDefault(c => c.KhoaID == item.KhoaID); Vlu_LopHoc objLop = ObjectContext.Vlu_LopHoc.FirstOrDefault(c => c.LopID == item.LopID); if (objMH != null && objKhoa != null && objLop != null) { Vlu_ChuongTrinhDT obj = new Vlu_ChuongTrinhDT(); obj.ID = -1; obj.Vlu_MonHoc = objMH; obj.Vlu_Khoa = objKhoa; obj.Vlu_LopHoc = objLop; obj.NamHoc = item.NamHoc; obj.HocKy = item.HocKy; obj.NgayTao = DateTime.Now; obj.NguoiTao = ServiceContext.User.Identity.Name; obj.NgayCapNhat = DateTime.Now; obj.NguoiCapNhat = ServiceContext.User.Identity.Name; result++; ObjectContext.AddToVlu_ChuongTrinhDT(obj); } } if (result > 0) { ObjectContext.SaveChanges(); } return(result); }