public string Delete(Course course) { if (_courseRepository.Records.Any(c => c.Id == course.Id)) { if (_lectureCourseRepository.Records.Any(lc => lc.CourseId == course.Id)) { var lecturecourses = _lectureCourseRepository.Records.Where(lc => lc.CourseId == course.Id); _lectureCourseRepository.Records.RemoveRange(lecturecourses); _lectureCourseRepository.SaveChanges(); } //-------------------------------------------------------------- if (_studentCourseRepository.Records.Any(sc => sc.CourseId == course.Id)) { var studentcourses = _studentCourseRepository.Records.Where(sc => sc.CourseId == course.Id); _studentCourseRepository.Records.RemoveRange(studentcourses); _studentCourseRepository.SaveChanges(); } //---------------------------------------------------------------- _courseRepository.Delete(course); return("successfully deleted"); } else { return("failed"); } }
public string Delete(Student student) { if (_studentRepository.Records.Any(s => s.Id == student.Id)) { if (_studentCourseRepository.Records.Any(sc => sc.StudentId == student.Id)) { var studentcourses = _studentCourseRepository.Records.Where(sc => sc.StudentId == student.Id); _studentCourseRepository.Records.RemoveRange(studentcourses); _studentCourseRepository.SaveChanges(); } _studentRepository.Delete(student); return("successfully deleted"); } else { return("No such student"); } }