public ICommandResult Handle(AddClassroomCommand command)
        {
            command.Validate();

            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "Erro ao vincular aula ao aluno", Notifications));
            }

            var classroom = _classroomRepository.GetById(command.ClassroomId);
            var student   = _studentRepository.GetById(command.StudentId);


            AddNotifications(new Contract()
                             .Requires()
                             .IsNotNull(student, "StudentId", "O ID do aluno é inválido ou não existe")
                             .IsNotNull(classroom, "ClassroomId", "O ID da aula é inválido ou não existe"));

            var studentsClassrooms = new StudentsClassrooms(student, classroom);

            AddNotifications(student, classroom, studentsClassrooms);

            if (Invalid)
            {
                return(new CommandResult(false, "Erro ao vincular aula ao aluno", Notifications));
            }

            _studentRepository.AddClassroom(studentsClassrooms);

            return(new CommandResult(true, "Aula vinculada ao aluno.", command));
        }
예제 #2
0
 public Classroom GetClassroomById(int courseId)
 {
     return(_classroomRepository.GetById(courseId));
 }
 public ClassroomViewModel GetById(int classroomId)
 {
     return(classroomRepository.GetById(classroomId).ToClassroomView());
 }