public async Task CreateCourse(CourseDb course) { CourseStudentDb courseStudent = new CourseStudentDb() { Course = course, }; _context.Add(course); try { await _context.SaveChangesAsync(); } catch (Exception ex) { throw new DBOperationException(ex); } }
public async Task StudentEnrollCourse(int studentId, int courseId) { CourseStudentDb courseStudent = new CourseStudentDb() { StudentId = studentId, CourseId = courseId, }; if (_context.CourseStudents.Any(x => x.CourseId == courseId && x.StudentId == studentId)) { return; } _context.Add(courseStudent); try { await _context.SaveChangesAsync(); } catch (Exception ex) { throw new DBOperationException(ex); } }