Example #1
0
        public ICommandResult Handle(CreateCreditCardSubscriptionCommand command)
        {
            // Fail Fast Validations
            command.Validate();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "Não foi possível realizar sua assinatura"));
            }

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

            // Verificar se Email já está cadastrado
            if (_studentRepository.DocumentExists(command.Email))
            {
                AddNotification("Email", "Este Email 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 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 CreditCardPayment(command.CardHolderName, command.CardNumber, command.LastTransactionNumber,
                                                     command.PaidDate, command.ExpireDate,
                                                     command.Total, command.TotalPaid,
                                                     command.Payer, new Document(command.PayerDocuments,
                                                                                 command.PayerDocumentsType), address, email);

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

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

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

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

            // Enviar E-mail de boas vindas
            _emailService.Send(student.Name.ToString(), student.Email.Address, "Bem vindo ao Curso", "Sua assinatura foi assinada");
            // Retornar informações

            return(new CommandResult(true, "Assinatura realizada com sucesso"));
        }
        public ICommandResult Handle(CreateCreditCardSubscriptionCommand command)
        {
            //Fail Fast validations
            command.Validate();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "Não foi possível realizar sua assinatura"));
            }

            //Verificar se documento já esta cadastrado
            if (_repository.DocumentExists(command.Document))
            {
                AddNotification("Documents", "Este CPF já se encontra cadastrado");
            }
            //Verificar se email já esta cadastrado
            if (_repository.DocumentExists(command.Email))
            {
                AddNotification("Documents", "Este E-mail já se encontra cadastrado");
            }
            //Gerar VO
            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, address);
            var subscription = new Subscription(DateTime.Now.AddMonths(1));
            var payment      = new CreditCardPayment(command.Owner,
                                                     command.CardNumber,
                                                     command.LastTransactionNumber,
                                                     command.PaidDate,
                                                     command.ExipreDate,
                                                     command.Total,
                                                     command.TotalPaid,
                                                     new Document(command.OwnerDocument, command.OwnerType),
                                                     command.Owner,
                                                     address,
                                                     email);

            //Relacionamentos
            subscription.AddPayment(payment);
            student.AddSubscritpion(subscription);
            //Aplicar Validações
            AddNotifications(name, document, email, address, student, subscription, payment);
            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possível realizar sua assinatura"));
            }
            //Salvar Informações
            _repository.CreateSubscrption(student);
            //Enviar E-mail
            _emailService.Send(student.Name.ToString(), student.Email.Address, "Bem vindo ao Site", "Sua Assinatura foi criada");

            return(new CommandResult(true, "Assinatura Realizada com sucesso"));
        }
Example #3
0
        public void ShouldReturnErrorWhenNameIsInvalid()
        {
            var command = new CreateCreditCardSubscriptionCommand();

            command.FirstName = "";

            command.Validate();
            Assert.AreEqual(false, command.Valid);
        }
Example #4
0
        public ICommandResult Handle(CreateCreditCardSubscriptionCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "Não foi possível realizar sua assinatura"));
            }

            if (_repository.DocumentExists(command.Document))
            {
                AddNotification("Document", "Este CPF já está em uso");
            }

            if (_repository.EmailExists(command.Email))
            {
                AddNotification("Email", "Este E-mail já está em uso");
            }

            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);

            var student      = new Student(name, document, email);
            var subscription = new Subscription(DateTime.Now.AddMonths(1));
            var payment      = new CreditCardPayment(
                command.CardHolderName,
                command.CardNumber,
                command.LastTransactionNumber,
                command.PaidDate,
                command.ExpireDate,
                command.Total,
                command.TotalPaid,
                command.Payer,
                new Document(command.PayerDocument, command.PayerDocumentType),
                address,
                email
                );

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

            AddNotifications(name, document, email, address, student, subscription, payment);

            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possível realizar sua assinatura"));
            }

            _repository.CreateSubscription(student);

            _emailService.Send(student.Name.ToString(), student.Email.Address, "Bem vindo ao balta.io", "Sua assinatura foi criada!");

            return(new CommandResult(true, "Assinatura realizada com sucesso"));
        }
Example #5
0
        public ICommandResult Handle(CreateCreditCardSubscriptionCommand command)
        {
            //CREATE FAIL FAST VALIDATIONS

            //Verify if document has been saved
            if (_repository.DocumentExists(command.Document))
            {
                AddNotification("Document", "Este CPF ja esta em uso");
            }

            //verifify if e-mail has been saved
            if (_repository.EmailExists(command.Email))
            {
                AddNotification("E-mail", "Este E-mail ja esta em uso");
            }

            //Create 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);

            //Create Entities
            var student      = new Student(name, document, email);
            var subscription = new Subscription(DateTime.Now.AddMonths(1));
            var payment      = new CreditCardPayment(command.CardHolderName,
                                                     command.CardNumber,
                                                     command.LastTransactionNumber,
                                                     command.PaidDate,
                                                     command.ExpireDate,
                                                     command.Total,
                                                     command.TotalPaid,
                                                     command.Payer,
                                                     new Document(command.Document, EDocumentType.CPF),
                                                     address,
                                                     email
                                                     );

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

            //Group validations
            AddNotifications(name, document, email, address, student, subscription, payment);

            //Save information
            _repository.CreateSubscriprion(student);

            //Send welcome e-mail
            _emailService.Send(student.Name.ToString(), student.Email.Address, "Welcome", "Your subscription has been created");

            //return information
            return(new CommandResult(true, "Subscription success"));
        }
Example #6
0
        public ICommandResult Handle(CreateCreditCardSubscriptionCommand command)
        {
            //verificar se o doc ta cadastrado
            if (_repository.DocumentExists(command.Document))
            {
                AddNotification("Document", "Este CPF já esta em uso");
            }

            //verificar se o email ta cadastrado
            if (_repository.DocumentExists(command.Email))
            {
                AddNotification("Email", "Este Email já esta em uso");
            }

            //gerar as 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.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 CreditCardPayment(
                command.CardHolderName,
                command.CardNumber,
                command.LastTransactionNumber,
                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);

            //salvar as infos
            _repository.CreateSubscription(student);

            //enviar email boas vindas
            _emailService.Send(student.Name.ToString(), student.Email.Address, "Bem vindo novato!!", "Assinatura Criada");
            //retornar infos
            return(new CommanResult(true, "Assinatura cadastrada com sucesso!"));
        }
        public ICommandResult Handle(CreateCreditCardSubscriptionCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "não foi possível realizar seu cadastro"));
            }

            //verificar se o documento já existe
            if (_repository.DocumentExists(command.Document))
            {
                AddNotifications(command);
                return(new CommandResult(false, "já existe um cadastro com o documento informado"));
            }

            //verificar se email já existe
            if (_repository.EmailExists(command.Email))
            {
                AddNotifications(command);
                return(new CommandResult(false, "já existe um cadastro com o e-mail informado"));
            }

            //gerar 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 entidades
            var student      = new Student(name, document, email);
            var subscription = new Subscription(DateTime.Now.AddMonths(1));
            var payment      = new CreditCardPayment(command.CardHolderName, command.CardNumber, command.LastTransactionNumber, command.PaidDate, command.ExpireDate, command.Total, command.TotalPaid, address,
                                                     new Document(command.PayerDocument, command.PayerDocumentType), command.Payer, email);

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

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

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

            //Enviar email de boas vindas
            _emailService.Send(student.Name.ToString(), student.Email.Address, "bem vindo ao serviceName", "Sua assinatura foi criada!");

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


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


            //Gerar os values Objects (VOs)
            var name     = new Name(command.FirstName, command.LastName);
            var document = new Document(command.PayerDocument, EDocumentType.CPF);
            var email    = new Email(command.PayerEmail);
            var address  = new Address(command.Stret, command.Number, command.Neighborhood, command.City, command.State, command.Contry, command.zipCode);

            //Gerar as entidades
            var student          = new Entities.Student(name, email, document);
            var subscription     = new Entities.Subscription(DateTime.Now.AddMonths(1));
            var CreditCarpayment = new Entities.PayPalPayment(command.LastTransictionNumber, command.Number,
                                                              command.PaidDate, command.ExpireDate, command.Total, command.TotalPaid, command.Payer,
                                                              new Document(command.Payer, command.PayerDocumentType), address, email);

            // Adiciona os Relacionamentos
            subscription.AddPayment(CreditCarpayment);
            student.AddSubscription(subscription);

            // Agrupa as validações
            AddNotifications(name, document, address, student, subscription, CreditCarpayment);

            //checar as infos
            if (Invalid)
            {
                new CommandResult(false, "Assinatura realizada com suesso");
            }

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

            //Enviar E-mail de boas vindas
            _emailService.Send(student.Name.ToString(), student.Email.Address, "Bem vindo ao Beludo", "Sua assinatura foi criada");

            //Retornar informações
            return(new CommandResult(true, "Assinatura realizada com sucesso"));
        }
Example #9
0
        public ICommandResult Handle(CreateCreditCardSubscriptionCommand command)
        {
            //Verify whether document is already registred
            if (_repository.DocumentExists(command.Document))
            {
                AddNotification("Document", "Este CPF ja esta em uso");
            }

            //Verify whether eamil is already registred
            if (_repository.EmailExists(command.Email))
            {
                AddNotification("Email", "Este Email ja esta em uso");
            }

            //Generate 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.City, command.State, command.Country, command.ZipCode);

            //Generate Entities
            var student      = new Student(name, document, email);
            var subscription = new Subscription(DateTime.Now.AddMonths(1));
            var payment      = new CreditCardPayment(command.CardHolderName, command.CardNumber, command.LastTransactionNumber,
                                                     command.PaidDate, command.ExpireDate, command.Total, command.TotalPaid, command.Payer,
                                                     new Document(command.PaymentNumber, command.PayerDocumentType),
                                                     address, email);

            //Apply Relationship
            subscription.AddPayment(payment);
            student.AddSubcription(subscription);

            //Group Validation
            AddNotifications(name, document, email, address, student, subscription, payment);

            //Check notifications
            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possivel realizar sua assinatura."));
            }

            //Save information
            _repository.CreateSubscription(student);

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

            //Return information
            return(new CommandResult(true, "Assinatura realizada com sucesso."));
        }
Example #10
0
        public ICommandResult Handle(CreateCreditCardSubscriptionCommand command)
        {
            if (_studentRepository.DocumentExists(command.Document))
            {
                AddNotification("Document", "Document already in use");
            }

            if (_studentRepository.EmailExists(command.Email))
            {
                AddNotification("Email", "E-mail already in use");
            }

            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);

            var student      = new Student(name, document, email);
            var subscription = new Subscription(DateTime.Now.AddMonths(1));
            var payment      = new CreditCardPayment(command.PaidDate,
                                                     command.ExpireDate,
                                                     command.Total,
                                                     command.TotalPaid,
                                                     command.Payer,
                                                     new Document(command.PayerDocument, command.PayerDocumentType = EDocumentType.CPF),
                                                     address,
                                                     email,
                                                     command.CardHolderName,
                                                     command.CardNumber,
                                                     command.LastTransactionNumber);

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

            AddNotifications(name, document, email, address, student, subscription, payment);

            _studentRepository.CreateSubscription(student);

            _emailService.Send(student.Name.ToString(),
                               student.Email.Address,
                               $"Welcome {student.Name.ToString()}!",
                               "Your subscription has been approved. Go ahead and create your study plan.");

            return(new CommandResult(true, "Subscription successful added"));
        }
Example #11
0
 public ICommandResult Handle(CreateCreditCardSubscriptionCommand command)
 {
     throw new NotImplementedException();
 }
        public ICommandResult Handle(CreateCreditCardSubscriptionCommand command)
        {
            // fail fast validation
            command.Validate();

            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "It's not possible to realize your subscribe."));
            }

            // verify if the document is already exists (go in database)
            if (_Repository.DocumentExists(command.PayerDocument))
            {
                AddNotifications(command);
                return(new CommandResult(false, "CPF already exists."));
            }


            // verify if e-mail is already registered
            if (_Repository.EmailExists(command.PayerEmailAddress))
            {
                AddNotifications(command);
                return(new CommandResult(false, "Email already exists."));
            }

            // generate VO's
            var name     = new Name(command.FirstName, command.LastName);
            var email    = new Email(command.PayerEmailAddress);
            var address  = new Address(command.PublicArea, command.Number, command.Neighborhood, command.City, command.State, command.Country, command.ZipCode);
            var document = new Document(command.PayerDocument, command.PayerDocumentType);

            // generate entities
            var student      = new Student(name, email, address, document);
            var subscription = new Subscription(DateTime.Now.AddMonths(1));
            var payment      = new CreditCard(
                command.PaidDate,
                command.ExpireDate,
                new Document(command.PayerDocument, command.PayerDocumentType),
                command.Total,
                command.TotalPaid,
                command.Number,
                command.Owner,
                command.Limit,
                command.ChargingAddress,
                command.DueDate,
                command.CardExpireDate,
                command.Interest
                );

            // relationships
            subscription.AddPaymentMethod(payment);
            student.AddSubscription(subscription);

            // check notifications
            if (Invalid)
            {
                return(new CommandResult(false, "It's not possible to finalize your subscription."));
            }

            // join validations
            AddNotifications(name, document, email, address, student, subscription, payment);

            // save informations
            _Repository.CreateSubscription(student);

            // send welcome email
            _EmailService.send(student.ToString(), student.Email.Address, "Congratulations for subscribing", "Welcome!");

            // return infos
            return(new CommandResult(true, "Subscribe done with success"));
        }
        public ICommandResult Handle(CreateCreditCardSubscriptionCommand command)
        {
            var payment = new CreditCardPayment(command.PaiedDate, command.ExpireDate, command.Total, command.TotalPayed, address, command.Payer, document, email, command.CardHolderName, command.CardNumber, command.LastTransactionNumber);

            return(CreateSubscription(command, payment));
        }
        public ICommandResult Handle(CreateCreditCardSubscriptionCommand command)
        {
            //Fail Fast Validations
            command.Validate();
            if (command.Invalid)
            {
                AddNotifications(command);
                return(new CommandResult(false, "Não foi possível realizar o cadastro"));
            }

            //Check if document is already registered
            if (_repository.DocumentExists(command.Document))
            {
                AddNotification("Document", "Este documento já está em uso");
            }

            //Check if email is already registered
            if (_repository.EmailExists(command.Email))
            {
                AddNotification("Email", "Este e-mail já está em uso");
            }

            //Create 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.StreetNumber, command.Neighborhood, command.City, command.State, command.Country, command.ZipCode);
            var payerDocument = new Document(command.PayerDocument, command.PayerDocumentType);

            //Create Entitites
            var student      = new Student(name, document, email);
            var subscription = new Subscription(command.ExpireDate);
            var payment      = new CreditCardPayment(
                command.CardHolderName,
                command.CardNumber,
                command.LastTransactionNumber,
                command.PaidDate,
                command.ExpireDate,
                command.Total,
                command.TotalPaid,
                address,
                payerDocument,
                command.Payer,
                email);

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

            //Apply Validations
            AddNotifications(name, document, email, address, student, subscription, payment);

            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possível realizar sua assinatura"));
            }

            //Save data
            _repository.CreateSubscription(student);

            //Sent Welcome email
            _emailService.Send(student.Name.ToString(), student.Email.Address, "Bem-vindo!", "Sua assinatura foi criada");

            //Return
            return(new CommandResult(true, "Assinatura realizada com sucesso"));
        }
Example #15
0
        public ICommandResult Handle(CreateCreditCardSubscriptionCommand 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 CreditCardPayment(
                cardHolderName: command.CardHolderName,
                finalCardNumbers: command.FinalCardNumbers,
                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."));
        }