public IResult Handle(CreateCustomerCommand command)
        {
            //transações de negócios, regras de negócio, comunicação com outros handlers
            //Criacao dos objetos
            var name     = new NameVo(command.Nome, command.Sobrenome);
            var cpf      = new CpfVo(command.Documento);
            var email    = new EmailVo(command.Email);
            var customer = new Customer(name, cpf, email, command.Telefone);

            //Validar
            AddNotifications(name.Notifications);
            AddNotifications(cpf.Notifications);
            AddNotifications(email.Notifications);

            if (Invalid)
            {
                return(new ApiContract(false,
                                       "Erro. Corrija os campos abaixo:",
                                       Notifications));
            }

            try
            {
                _repository.Save(customer, null);
            }
            catch (Exception ex)
            {
                //TO-DO: implementa log depois
                throw new Exception("Erro - Handler CustomerCommandHandler" + ex.Message);
            }

            return(new ApiContract(true, "Customer criado com sucesso!", null));
        }
示例#2
0
        public IResult Handle(ChangeCustomerCommand command)
        {
            //Criar ValueObjects
            var name  = new NameVo(command.Nome, command.Sobrenome);
            var cpf   = new CpfVo(command.Documento);
            var email = new Email(command.Email);
            //Criar
            var customer = new Customer(name, cpf, email, command.Telefone);

            //Validar
            AddNotifications(name.Notifications);
            AddNotifications(cpf.Notifications);
            AddNotifications(email.Notifications);

            if (Invalid)
            {
                return(new ApiContract(false,
                                       "Erro, corrija os seguintes problemas:",
                                       Notifications));
            }

            try
            {
                _repository.Save(customer, command.Id);
            }
            catch (Exception ex)
            {
                //TO-DO: implementar log real
                throw new Exception("Erro - Handler CustomerHandler" + ex.Message);
            }

            return(new ApiContract(true, "Customer criado com sucesso", null));
        }
示例#3
0
 public Customer(NameVo name, CpfVo cpf, EmailVo email, string phone)
 {
     Name       = name;
     Cpf        = cpf;
     Email      = email;
     Phone      = phone;
     _addresses = new List <Address>();
 }
示例#4
0
        public Customer Get(Guid id)
        {
            var name  = new NameVo("Ray", "Carneiro");
            var cpf   = new CpfVo("88041300081");
            var email = new EmailVo("*****@*****.**");

            return(new Customer(name, cpf, email, "(11) 99999-9999"));
        }
示例#5
0
        public Customer(NameVo name, CpfVo cpf, EmailVo email, string phone)
        {
            Id         = Guid.NewGuid();
            Name       = name;
            Cpf        = cpf;
            Email      = email;
            Phone      = phone;
            _addresses = new List <Address>();

            Validate();
        }
示例#6
0
 public Customer(
     NameVo name,
     CpfVo cpf,
     Email email,
     string telefone)
 {
     Name       = name;
     Cpf        = cpf;
     Email      = email;
     Telefone   = telefone;
     _addresses = new List <Address>();
 }
示例#7
0
        public void Setup()
        {
            //Simular dados
            var name  = new NameVo("Ray", "Carneiro");
            var cpf   = new CpfVo("15366015006");
            var email = new EmailVo("*****@*****.**");

            _teclado = new Product("Teclado Microsoft", "Melhor teclado", "teclado.jpg", 10M, 10);
            _mouse   = new Product("Mouse Microsoft", "Melhor mouse", "mouse.jpg", 5M, 10);
            _monitor = new Product("Dell", "Melhor monitor", "dell.jpg", 50M, 10);

            _customer = new Customer(name, cpf, email, "11-5555-5555");
            _order    = new Order(_customer);
        }
示例#8
0
        public void Setup()
        {
            //simulando dados reais
            var name  = new NameVo("Ray", "Carneiro");
            var cpf   = new CpfVo("88041300081");
            var email = new Email("*****@*****.**");

            _teclado = new Product("Teclado Microsoft", "Melhor teclado", "teclado.jpg", 10M, 10);
            _mouse   = new Product("Mouse Microsoft", "Melhor mouse", "mouse.jpg", 5M, 10);
            _monitor = new Product("Monitor Dell", "Melhor monitor", "dell.jpg", 50M, 10);

            _customer = new Customer(name, cpf, email, "(11) 95555-5555");
            _order    = new Order(_customer);
        }
        public void CreateCustomerCommandTests_CreateOrder_ShouldBeValid()
        {
            var command  = new CreateCustomerCommand();
            var name     = new NameVo("Ray", "Carneiro");
            var cpf      = new CpfVo("15366015006");
            var email    = new EmailVo("*****@*****.**");
            var customer = new Customer(name, cpf, email, command.Telefone);

            //Validar
            AddNotifications(name.Notifications);
            AddNotifications(cpf.Notifications);
            AddNotifications(email.Notifications);

            Assert.AreEqual(true, !Invalid);
        }
示例#10
0
        //To-DO: criar uma padrão para retorno com smart notification
        public string Execute(PlaceOrderInput order)
        {
            #region Obter dados do banco
            //Customer customer = _customerReadOnlyRepository.Get(customerId);
            //if (customer == null)
            //{
            //    AddNotification("Customer", "Customer does not exist.");
            //}
            #endregion

            //Simulando dados, não implementei acesso a dados
            var name  = new NameVo("Ray", "Carneiro");
            var cpf   = new CpfVo("15366015006");
            var email = new EmailVo("*****@*****.**");
            _customer = new Customer(name, cpf, email, "11-5555-5555");

            if (_customer.Invalid)
            {
                AddNotification("Cliente", "Erros identificados nos dados de cliente: ");
                return(_customer.Notifications.FirstOrDefault().Message);
            }

            _order = new Order(_customer);
            var product = new Product(order.ProductItem.Title, order.ProductItem.Description, order.ProductItem.Image, order.ProductItem.Price, 10);
            _order.AddItem(product, order.ProductItem.Quantity);

            if (_order.Invalid)
            {
                AddNotification("Pedido", "Erros identificados nos dados do seu pedido: ");
                return(_order.Notifications.FirstOrDefault().Message);
            }

            string orderId;

            try
            {
                orderId = _orderWriteOnlyRepository.PlaceOrder(_customer, _order);

                _kafkaProducer.Produce(orderId);
            }
            catch (Exception ex)
            {
                //TO-DO: Implement log
                throw;
            }

            return("Número do pedido: " + orderId);
        }
        public string Execute(PlaceOrderInput order)
        {
            //Simulação de dados e regras de negócios
            var name  = new NameVo("Ray", "Carneiro");
            var cpf   = new CpfVo("15366015006");
            var email = new EmailVo("*****@*****.**");

            _customer = new Customer(name, cpf, email, "11-5555-5555");

            if (_customer.Invalid)
            {
                AddNotification("Cliente", "Erros identificados nos dados de cliente: ");
                return(_customer.Notifications.FirstOrDefault().Message);
            }

            _order = new Order(_customer);
            var product = new Product(order.ProductItem.Title, order.ProductItem.Description, order.ProductItem.Image, order.ProductItem.Price, 10);

            _order.AddItem(product, order.ProductItem.Quantity);

            if (_order.Invalid)
            {
                AddNotification("Pedido", "Erros identificados nos dados do seu pedido: ");
                return(_order.Notifications.FirstOrDefault().Message);
            }

            string orderId;

            try
            {
                //Salva ordem no banco de dados
                orderId = _orderWriteOnlyRepository.PlaceOrder(_customer, _order);

                //Envia mensagem para Kafka
                _kafkaAdapter.Produce(orderId);
            }
            catch
            {
                throw;
            }

            return("Número do pedido: " + orderId);
        }
        public IResult Handle(CustomerDocumentQuery query)
        {
            var cpf = new CpfVo(query.Documento);

            AddNotifications(cpf.Notifications);

            if (Invalid)
            {
                return(new ApiContract(false,
                                       "Erro, corrija os seguintes problemas:",
                                       Notifications));
            }

            try
            {
                return(new ApiContract(true, string.Empty, _repository.GetByDocument(query.Documento)));
            }
            catch (Exception ex)
            {
                throw new Exception("Erro - Handler CustomerHandler" + ex.Message);
            }
        }
示例#13
0
 public void Setup()
 {
     _cpfValido   = new CpfVo("88041300081");
     _cpfInvalido = new CpfVo("12345678900");
 }
示例#14
0
 public void Setup()
 {
     _cpfValido   = new CpfVo("15366015006");
     _cpfInvalido = new CpfVo("123456789011");
 }