예제 #1
0
        public async Task AddCourseMemberAsync(int courseId, string teacherEmail)
        {
            bool teacherIsAlreadyAdded = courseRepository
                                         .GetCourseTeachers(courseId)
                                         .Any(t => t.User.Email == teacherEmail);

            if (teacherIsAlreadyAdded)
            {
                throw new BadRequestException("The teacher is already added!");
            }

            Teacher teacher = await teacherRepository.GetByEmailAsync(teacherEmail);

            Course course = await courseRepository.GetByIdAsync(courseId);

            if (teacher.UniversityId != course.UniversityId)
            {
                throw new BadRequestException("Teacher of another university can't be added to this course!");
            }

            await courseRepository.AddCourseMemberAsync(courseId, teacher.UserId);

            await courseRepository.SaveChangesAsync();
        }