コード例 #1
0
        public void AddStudentToCourse(AddStudentDTO dto)
        {
            var course = (from c in _db.Courses
                          join t in _db.CourseTemplate on c.TemplateID equals t.TemplateID
                          where c.Semester == dto.Semester
                          select c).SingleOrDefault();

            if (course == null)
            {
                throw new KeyNotFoundException();
            }

            var student = _db.Student.SingleOrDefault(x => x.SSN == dto.SSN);

            if (student == null)
            {
                throw new KeyNotFoundException();
            }

            Entities.StudentInCourse toInsert = new Entities.StudentInCourse();
            toInsert.CourseID  = course.ID;
            toInsert.StudentID = student.SSN;

            _db.StudentInCourse.Add(toInsert);
            _db.SaveChanges();
        }
コード例 #2
0
        public void AddStudentToCourse(AddStudentDTO dto)
        {
            var course = (from c in _db.Courses
                          join t in _db.CourseTemplate on c.TemplateID equals t.TemplateID
                          where c.Semester == dto.Semester
                          select c).SingleOrDefault();

            if (course == null)
                throw new KeyNotFoundException();

            var student = _db.Student.SingleOrDefault(x => x.SSN == dto.SSN);

            if (student == null)
            {
                throw new KeyNotFoundException();
            }

            Entities.StudentInCourse toInsert = new Entities.StudentInCourse();
            toInsert.CourseID = course.ID;
            toInsert.StudentID = student.SSN;

            _db.StudentInCourse.Add(toInsert);
            _db.SaveChanges();
        }