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

            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "Não foi possível cadastrar o aluno", Notifications));
            }
            var motherName = new Name(
                command.MotherFirstName,
                command.MotherLastName,
                command.MotherRG,
                command.MotherCPF);

            var fatherName = new Name(
                command.FatherFirstName,
                command.FatherLastName,
                command.FatherRG,
                command.FatherCPF);

            var studentName = new Name(
                command.StudentFirstName,
                command.StudentLastName,
                command.StudentRG,
                command.StudentCPF);

            var payment = new Payment(
                command.PaymentFee,
                command.PaymentExpirationDay);


            var student = _studentRepository.GetById(command.Id);

            AddNotifications(new Contract()
                             .Requires()
                             .IsNotNull(student, "student", "O aluno não existe"));

            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possível alterar o aluno", Notifications));
            }

            student.UpdateStudent(
                fatherName,
                motherName,
                payment,
                studentName,
                command.Email,
                command.BirthDate,
                command.Gender,
                command.Notes);


            AddNotifications(motherName, fatherName, studentName, payment, student);

            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possível alterar o aluno", Notifications));
            }

            _studentRepository.UpdateStudent(student);

            return(new CommandResult(true, "Aluno alterado com sucesso",
                                     new { Id = student.Id, Name = student.Name.ToString() }));
        }
Пример #2
0
        // Editar um aluno
        public ICommandResult Handle(UpdateStudentCommand command)
        {
            // Variaveis necessarias
            Student  student        = new Student();
            Parent   parent         = new Parent();
            Document parentDocument = new Document();
            Email    parentEmail    = new Email();

            // Valida os dados do command
            command.Validate();

            // Se for invalido, mostrar as notificações
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, SharedMessages.InvalidOperation, command));
            }

            // Preenchendo os VOs do aluno
            var studentName    = new Name(command.FirstName, command.LastName);
            var studentAddress = new Address(command.Street,
                                             command.Number,
                                             command.Neighborhood,
                                             command.City,
                                             command.StateName,
                                             command.Coutry,
                                             command.ZipCode,
                                             command.Abbr);

            // Preenchendo o objeto aluno
            student = new Student(studentName,
                                  studentAddress,
                                  command.BirthDate,
                                  command.ETypeOfEducation,
                                  command.AcademicYear,
                                  command.Serie,
                                  command.Grade,
                                  command.Shifts,
                                  command.CalledNumber,
                                  command.Note);
            student.ChangeId(command.Id);
            student.SetSchoolId(command.SchoolId);

            //Preenchendo o objeto dos responsáveis
            for (int i = 0; i < command.Parents.Count; i++)
            {
                // Preenchendo os VOs do responsável
                parentDocument = new Document(command.Parents[i].DocumentNumber, command.Parents[i].Type);
                parentEmail    = new Email(command.Parents[i].AddressEmail);

                // Preenchendo o objeto responsável
                parent = new Parent(command.Parents[i].ResponsibleName,
                                    parentDocument,
                                    command.Parents[i].EFamilyType,
                                    parentEmail,
                                    command.Parents[i].Telephone);
                parent.ChangeId(command.Parents[i].Id);
                parent.AddUpdateAlternativeTelephone(command.Parents[i].AlternativeTelephone);
                parent.AddUpdateContactTelephone(command.Parents[i].ContactTelephone);

                // Adicionando o responsável ao aluno
                student.AddParents(parent);
            }

            // Caso algum deles retorne erro, mostre as notificações
            AddNotifications(parentDocument, parentEmail, parent,
                             studentName, studentAddress, student);

            // Checando as notificações
            if (Invalid)
            {
                return(new CommandResult(false, SharedMessages.InvalidOperation, student));
            }

            // Adicionando ao contexto o objeto aluno
            _studentRepository.Update(student);

            // Realizando a confirmação do salvamento do objeto
            _uow.Commit();

            // Retornando informações de sucesso e o objeto preenchido
            return(new CommandResult(true, SharedMessages.SuccedOperation, student));
        }