public Lesson BookNewLesson(Lesson lessonDetails, int teacherId) { if (lessonDetails.StudentId == null) { throw new Exception("StudentId cannot be null."); } int studentId = lessonDetails.StudentId.Value; IList <Student> studentsInClass = StudentsRepository.GetAllStudentsByTeacher(teacherId); IList <int> studentIdsList = studentsInClass.Select(s => s.StudentId).ToList(); if (!studentIdsList.Contains(studentId)) { throw new Exception("You cannot book a lesson for this student."); } lessonDetails.UserId = teacherId; Lesson bookedLesson = LessonsRepository.CreateNewLesson(lessonDetails); return(bookedLesson); }
public IList <Student> GetAllStudentsByTeacher(int teacherId) { return(StudentsRepository.GetAllStudentsByTeacher(teacherId)); }