Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
            }
        }