public IActionResult EditCourses(int StudentId, List <EditStudentCoursesViewModel> model) { if (StudentId == 0) { return(View("NotFound")); } for (int i = 0; i < model.Count; i++) { if (model[i].IsSelected == true && !(studentCourseRepository.IsRelationExist(StudentId, model[i].CourseId))) { var studentCourseRelation = new StudentCourseRelation { StudentId = StudentId, CourseId = model[i].CourseId }; studentCourseRepository.Add(studentCourseRelation); } else if (model[i].IsSelected == false && studentCourseRepository.IsRelationExist(StudentId, model[i].CourseId)) { studentCourseRepository.Delete(StudentId, model[i].CourseId); } else { continue; } } return(RedirectToAction("Details", new { id = StudentId })); }
public bool DeleteCourse(int id) { if (_courseRepository.Records.Any(x => x.Id == id)) { var studentCourse = _studentCourseRepository.Records.Where(x => x.CourseId == id).ToList(); foreach (var item in studentCourse) { var student = _studentRepository.GetById(item.StudentId); student.Credit += 4; _studentRepository.Update(student); _studentCourseRepository.Delete(item); } var lecturerCourse = _lecturerCourseRepository.Records.Where(x => x.CourseId == id).ToList(); foreach (var item in lecturerCourse) { _lecturerCourseRepository.Delete(item); } _courseRepository.Delete(_courseRepository.GetById(id)); return(true); } else { return(false); } }
public bool Delete(int id) { if (_studentRepository.Records.Any(x => x.Id == id)) { var courses = _studentCourseRepository.Records.Where(x => x.StudentId == id).ToList(); foreach (var course in courses) { _studentCourseRepository.Delete(course); } _studentRepository.Delete(_studentRepository.GetById(id)); return(true); } else { return(false); } }