public Course AddCourse(Course course) { try { _cycodeContext.Courses.Add(course); _cycodeContext.SaveChanges(); return(course); } catch (DbException e) { throw new DALException("There was a problem adding course to DB", e); } }
public Grade AddGrade(Grade grade) { try { _cycodeContext.Grades.Add(grade); _cycodeContext.SaveChanges(); return(grade); } catch (DbException e) { throw new DALException("There was a problem adding grade to DB", e); } }
public Student AddStudent(Student student) { try { _cycodeContext.Students.Add(student); _cycodeContext.SaveChanges(); return(student); } catch (DbException e) { throw new DALException("There was a problem adding student to DB", e); } }
public StudentInCourse GetOrCreateStudentInCourse(int studentId, int courseId) { try { var studentInCourse = _cycodeContext.StudentInCourses.SingleOrDefault(sic => sic.CourseId == courseId && sic.StudentId == studentId); if (studentInCourse == null) { studentInCourse = new StudentInCourse { StudentId = studentId, CourseId = courseId }; _cycodeContext.StudentInCourses.Add(studentInCourse); _cycodeContext.SaveChanges(); } return(studentInCourse); } catch (DbException e) { throw new DALException("There was a problem getting or creating student in course", e); } }