示例#1
0
        /// <summary>
        /// Delete a teaching assignment
        /// </summary>
        /// <param name="teaching"></param>
        /// <returns></returns>
        public TeachingDto DeleteTeachingAssignment(TeachingDto teaching)
        {
            Teaching deletedTeaching = teachingsService.Value.DeleteTeaching(teaching);

            db.TeachingAssignmentsRepository.Delete(deletedTeaching);
            db.Save();

            var dto = TeachingsConverter.TeachingToTeachingDto(deletedTeaching);

            return(dto);
        }
示例#2
0
        /// <summary>
        /// Get teaching assignment
        /// </summary>
        /// <param name="courseId"></param>
        /// <param name="teacherId"></param>
        /// <returns></returns>
        public TeachingDto GetTeaching(int courseId, int teacherId)
        {
            // I probably dont need these. Just return null if there's no teaching
            Course course = db.CoursesRepository.GetByID(courseId);

            // No null check here, because the teachers service takes care of that...!
            TeacherUser teacher = teachersService.Value.GetTeacherById(teacherId);

            // Probably teaching will get Course and TeacherUser, so failure will be there!
            Teaching teaching = teachingsService.Value.GetTeaching(courseId, teacherId);

            if (teaching == null)
            {
                return(null);
            }

            return(TeachingsConverter.TeachingToTeachingDto(teaching));
        }
示例#3
0
        /// <summary>
        /// This should be the default entry for teaching assignments
        /// </summary>
        /// <param name="teaching"></param>
        /// <returns></returns>
        public TeachingDto CreateTeachingAssignment(TeachingDto teaching)
        {
            Course course = GetCourseById(teaching.CourseId);

            TeacherUser teacher = teachersService.Value.GetTeacherById(teaching.TeacherId);

            // Without teacher & user
            //      1) required must be withheld
            //      2) if teacher or course id is not valid, there will be a foreign key violation
            //      3) if there is already a teaching assignment, a unique constraint will fire

            Teaching newTeaching = new Teaching()
            {
                Course  = course,
                Teacher = teacher
            };

            db.TeachingAssignmentsRepository.Insert(newTeaching);
            db.Save();

            return(TeachingsConverter.TeachingToTeachingDto(newTeaching));
        }