public bool chkOverlap(Classroom classroom) { bool overlap = false; //find classroom and check if there is overlap var chkClassroom = _classroomRepository.Query().Where(x => x.ClassroomName == classroom.ClassroomName); if (chkClassroom != null) { foreach (var item in chkClassroom) { if (classroom.StartDate == item.StartDate) { overlap = classroom.StartTime < item.EndTime && item.StartTime < classroom.EndTime; if (overlap) { break; } } } } //find course and check overlap var chkCourse = _classroomRepository.Query().Where(x => x.CourseId == classroom.SelectedCourse); if (chkCourse != null) { foreach (var item in chkCourse) { if (classroom.StartDate == item.StartDate) { overlap = classroom.StartTime < item.EndTime && item.StartTime < classroom.EndTime; if (overlap) { break; } } } } return(overlap); }