Example #1
0
        public ICommandResult Handle(AddCustomerCommand command)
        {
            // Verificar se o CPF já existe
            if (_customerRepository.checkDocumentExists(command.documentNumber))
            {
                AddNotification("Document", "Este CPF já está em uso!");
                return(null);
            }

            // Verificar se o email já existe
            if (_customerRepository.checkEmailExists(command.emailAddress))
            {
                AddNotification("Email", "Este email já está em uso!");
                return(null);
            }

            // Gerar o novo cliente
            var document = new DocumentVo(command.documentNumber);
            var email    = new EmailVo(command.emailAddress);
            var address  = new AddressVo(
                command.addressStreet,
                command.addressNumber,
                command.addressNeighborhood,
                command.addressCity,
                command.addressState,
                command.addressZipCode
                );
            var customer = new CustomerEntity(
                command.name,
                command.birthDate,
                document,
                address,
                email,
                DateTime.Now);

            // Adicionar as notificação
            AddNotifications(document.Notifications);
            AddNotifications(email.Notifications);
            AddNotifications(address.Notifications);
            AddNotifications(customer.Notifications);

            if (this.Invalid)
            {
                return(null);
            }

            // Inserir no banco
            _customerRepository.save(customer);

            // Enviar E-mail de boas vindas

            /*_emailService.Send(
             *  customer.Name.ToString(),
             *  customer.Email.Address,
             *  string.Format(EmailTemplates.WelcomeEmailTitle, customer.Name),
             *  string.Format(EmailTemplates.WelcomeEmailBody, customer.Name));*/

            return(new AddCustomerCommandResult(customer.id.ToString()));
        }
Example #2
0
        public ICommandResult Handle(EditCustomerCommand command)
        {
            var oldCustomer = _customerRepository.getById(command.id);

            // Verificar se existe o cliente
            if (oldCustomer == null)
            {
                AddNotification("Customer", "Cliente não encontrado");
                return(null);
            }

            // Gerar o novo cliente
            var document = new DocumentVo(command.documentNumber);
            var email    = new EmailVo(command.emailAddress);
            var address  = new AddressVo(
                command.addressStreet,
                command.addressNumber,
                command.addressNeighborhood,
                command.addressCity,
                command.addressState,
                command.addressZipCode
                );
            var customer = new CustomerEntity(
                command.name,
                command.birthDate,
                document,
                address,
                email,
                oldCustomer.createAt,
                id: oldCustomer.id);

            // Adicionar as notificação
            AddNotifications(document.Notifications);
            AddNotifications(email.Notifications);
            AddNotifications(address.Notifications);
            AddNotifications(customer.Notifications);

            if (this.Invalid)
            {
                return(null);
            }

            // altera
            _customerRepository.update(customer);

            return(new AddCustomerCommandResult(customer.id.ToString()));
        }
Example #3
0
        public CustomerEntity(
            string name,
            DateTime?birthDate,
            DocumentVo document,
            AddressVo address,
            EmailVo email,
            DateTime createAt,
            Guid?id = null) : base(id: id, createAt: createAt)
        {
            this.name      = name;
            this.birthDate = birthDate;
            this.document  = document;
            this.address   = address;
            this.email     = email;

            AddNotifications(new Contract()
                             .IsNotNullOrEmpty(name, "CustomerEntity.name", "Nome é obrigatório")
                             );
        }