public ICommandResult Handle(CreatePaypalSubscriptionCommand command)
        {
            // command.Validate();
            // if (command.Invalid)
            // {
            //     AddNotifications(command);
            //     return new CommandResult(false, "Não foi possível realizar sua assinatura");
            // }

            // Verificar se documento já estpa cadastrado
            if (_repository.DocumentExists(command.Document))
            {
                AddNotification("Document", "CPF já utilizado");
            }

            // Verificar se E-mail já está cadastrado
            if (_repository.EmailExists(command.Email))
            {
                AddNotification("Email", "CPF já utilizado");
            }

            // GErar VOs
            var name     = new Name(command.FirstName, command.LastName);
            var document = new Document(command.Document, EDocumentType.CPF);
            var email    = new Email(command.Email);
            var address  = new Address(command.Street, command.Number, command.Neighborhood, command.State, command.Country, command.ZipCode);

            // Gerar Entidades
            var student      = new Student(name, document, email);
            var subscription = new Subscription(DateTime.Now.AddMonths(1));
            var payment      = new PayPalPayment(
                command.TransactionCode, command.PaidDate, command.ExpireDate,
                command.Total, command.TotalPaid, command.Payer,
                new Document(command.PayerDocument, command.PayerDocumentType),
                address, email
                );

            //Relacionamentos
            subscription.AddPayment(payment);
            student.AddSubscription(subscription);

            // Agrupar Validações
            AddNotifications(name, document, email, address, student, subscription, payment);

            if (Invalid)
            {
                return(new CommandResult(false, "ass false"));
            }

            // Salvar informações
            _repository.CreateSubscription(student);

            // Enviar e-mail de boas vindas
            _emailService.Send(student.Name.ToString(), student.Email.Address, "welcome", "ass ok");
            //Retornar informacoes

            return(new CommandResult(true, "Assinatura realizada com sucesso"));
        }
Example #2
0
        public ICommandResult Handle(CreatePaypalSubscriptionCommand command)
        {
            // verificar se documento já está cadastrado
            if (_repository.DocumentExists(command.Document))
            {
                AddNotification("Document", "Este CPF já está em uso");
            }

            // verificar se e-mail já está cadastrado
            if (_repository.EmailExists(command.Email))
            {
                AddNotification("Document", "Este e-mail já está em uso");
            }

            // gerar os VOs
            var name     = new Name(command.FirstName, command.LastName);
            var document = new Document(command.Document, EDocumentType.CPF);
            var email    = new Email(command.Email);
            var adress   = new Address(command.Street, command.Number, command.Neighborhood, command.City, command.State, command.Country, command.ZipCode);

            // gerar as entidades
            var student      = new Student(name, document, email);
            var subscription = new Subscription(DateTime.Now.AddMonths(1));
            var payment      = new PayPalPayment(
                command.TransactionCode,
                command.PaidDate,
                command.ExpireDate,
                command.Total,
                command.TotalPaid,
                new Document(command.PayerDocument, command.PayerDocumentType),
                command.Payer,
                adress,
                email
                );

            //Relacionamentos
            subscription.AddPayment(payment);
            student.AddSubscription(subscription);

            // agrupar as validações
            AddNotifications(name, document, email, adress, student, subscription, payment);

            // checar as notificações
            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possível realizar sua assinatura"));
            }

            // salvar as informações
            _repository.CreateSubstription(student);

            // enviar e-mail de boas vindas
            _emailService.Send(student.Name.ToString(), student.Email.Adress, "Bem vindo!", "Sua assinatura foi criada.");

            // retornar informações
            return(new CommandResult(true, "Assinatura realizada com sucesso"));
        }
        public ICommandResult Handle(CreatePaypalSubscriptionCommand command)
        {
            // Verificar se o documento está cadastrado.
            if (_repository.DocumentExists(command.Document))
            {
                AddNotification("Document", "Este CPF já está em uso.");
            }

            // Verificar se o email está cadastrado.
            if (_repository.DocumentExists(command.EMail))
            {
                AddNotification("EMail", "Este e-mail já está em uso.");
            }

            // Gerar os VO's
            var name     = new Name(command.FirstName, command.LastName);
            var document = new Document(command.Document, EDocumentType.CPF);
            var eMail    = new EMail(command.EMail);
            var address  = new Address(command.Street, command.Number, command.Neighborhood, command.City, command.Street, command.Country, command.Zip);

            // Gerar as entidades
            var student      = new Student(name, document, eMail);
            var subscription = new Subscription(DateTime.Now.AddMonths(1));
            var payment      = new PayPalPayment(
                command.TransactionCode,
                command.PaidDate,
                command.ExpireDate,
                command.Total,
                command.TotalPaid,
                address,
                command.Payer,
                //document,
                new Document(command.PayerDocument, command.PayerDocumentType),
                eMail);

            // Relacionamentos
            subscription.AddPayment(payment);
            student.AddSubscription(subscription);


            // Agrupar as validações
            AddNotifications(name, document, eMail, address, student, subscription, payment);

            // Salvar as informações
            _repository.CreateSubscription(student);

            // Enviar email de boas vindas
            _emailService.Send(student.Name.ToString(), student.EMail.Address, "Bem Vindo", "Sua assinatura foi criada.");

            // Retornar as informações
            return(new CommandResult(true, "Assinatura realizada com sucesso."));
        }
Example #4
0
 public ICommandResult Handle(CreatePaypalSubscriptionCommand command)
 {
     throw new NotImplementedException();
 }
Example #5
0
        public ICommandResult Handle(CreatePaypalSubscriptionCommand command)
        {
            // Fail Fast Validations
            command.Validate();
            AddNotifications(command);

            if (command.Invalid)
            {
                return(_failCommandResult);
            }

            // Verificar se o documento já está cadastrado
            if (_studentRepository.DocumentExists(command.Document))
            {
                AddNotification("Document", "Este documento já está em uso.");
                return(_failCommandResult);
            }

            // Verificar se o E-mail já está cadastrado
            if (_studentRepository.DocumentExists(command.EmailAddress))
            {
                AddNotification("EmailAddress", "Este E-mail já está em uso.");
                return(_failCommandResult);
            }

            // Gerar VOs
            var name     = new Name(command.FirstName, command.LastName);
            var email    = new Email(command.EmailAddress);
            var document = new Document(command.Document, EDocumentType.CPF);

            var address = new Address(
                street: command.Street,
                number: command.AddressNumber,
                neighborhood: command.Neighborhood,
                city: command.City,
                state: command.State,
                country: command.Country,
                zipCode: command.ZipCode
                );

            var payerDocument = new Document(
                command.PayerDocument,
                command.PayerDocumentType
                );

            // Gerar as entidades
            var student = new Student(name, document, email);

            var subscription = new Subscription(DateTime.Now.AddMonths(1));

            var payment = new PayPalPayment(
                email: email,
                transactionCode: command.TransactionCode,
                paidDate: command.PaidDate,
                expireDate: command.ExpireDate,
                total: command.Total,
                totalPaid: command.TotalPaid,
                payer: command.Payer,
                document: document,
                address: address
                );

            // Relacionamentos
            subscription.AddPayment(payment);
            student.AddSubscription(subscription);

            // Agrupar as validações
            AddNotifications(
                name,
                document,
                email,
                address,
                student,
                subscription,
                payment
                );

            // Verificar antes de salvar
            if (this.Invalid)
            {
                return(_failCommandResult);
            }

            // Salvar as informações
            _studentRepository.CreateSubscription(student);

            // Enviar E-mail de boas vindas
            _emailService.Send(
                to: student.Name.ToString(),
                email: student.Email.Address,
                subject: "Bem vindo ao balta.io.",
                body: "Sua assinatura foi realizada."
                );

            // Retornar informações
            return(new CommandResult(true, "Assinatura realizada com sucesso."));
        }
        public ICommandResult Handle(CreatePaypalSubscriptionCommand command)
        {
            //Fail Fast Validations.
            command.Validate();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "Não foi possível realizar a assinatura, por favor verifique os dados"));
            }
            // Verificar se documento já está cadastrado.
            if (_repository.DocumentExits(command.Document))
            {
                AddNotification("Document", "Este CPF já está em uso");
            }

            //Verificar se e-mail já está cadastrado.
            if (_repository.EmailExits(command.Email))
            {
                AddNotification("Email", "Este E-mail já está em uso");
            }

            // Gerar os VO's
            var name     = new Name(command.FirstName, command.LastName);
            var document = new Document(command.Document, EDocumentType.CPF);
            var email    = new Email(command.Email);
            var address  = new Address(command.Street, command.Number, command.Neighborhood, command.City, command.State, command.Country, command.ZipCode);

            //Gerar as entidades.
            var student      = new Student(name, document, email);
            var subscription = new Subscription(DateTime.Now.AddMonths(1));
            var payment      = new PaypalPayment(
                command.TransactionCode,
                command.PaidDate,
                command.ExpireDate,
                command.Total,
                command.TotalPaid,
                address,
                document,
                command.Payer,
                email);

            //Relacionamentos
            subscription.AddPayment(payment);
            student.AddSubscription(subscription);

            //Agrupar validações.
            AddNotifications(name, document, email, address, student, subscription, payment);

            //Checar as notificações
            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possível realizar a assinatura"));
            }

            //Salvar as informações.
            _repository.CreateSubscription(student);

            //Enviar e-mail.
            _emailService.Send(student.Name.ToString(), student.Email.Address, "Bem vindo ao Balta.io", "Sua assinatura foi criada");

            //Retornas informações.
            return(new CommandResult(true, "Assinatura realizada com sucesso"));
        }