Esempio n. 1
0
        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");
            }
        }
Esempio n. 2
0
        public string Delete(Lecturer lecture)
        {
            if (_lectureRepository.Records.Any(s => s.Id == lecture.Id))
            {
                if (_lectureCourseRepository.Records.Any(sc => sc.LecturerId == lecture.Id))
                {
                    var lecturecourses = _lectureCourseRepository.Records.Where(sc => sc.LecturerId == lecture.Id);

                    _lectureCourseRepository.Records.RemoveRange(lecturecourses);

                    _lectureCourseRepository.SaveChanges();
                }

                _lectureRepository.Delete(lecture);

                return("successfully deleted");
            }
            else
            {
                return("No such lecture");
            }
        }