Ejemplo n.º 1
0
        public override async Task <CreateCliente> HandleAsync(CreateCliente command, CancellationToken cancellationToken = new CancellationToken())
        {
            var cliente = ClienteFactory.CreateCliente(command.ClienteId, command.RagioneSociale, command.CodiceFiscale,
                                                       command.PartitaIva, command.Who, command.When);

            await this._repository.SaveAsync(cliente, Guid.NewGuid());

            return(await base.HandleAsync(command, cancellationToken));
        }
Ejemplo n.º 2
0
        public ClienteDTO AddCliente(ClienteDTO clienteDTO)
        {
            try
            {
                if (clienteDTO == null)
                {
                    throw new ArgumentNullException("ClienteDTO");
                }

                if (clienteDTO.Cnpj != null)
                {
                    clienteDTO.Cnpj = clienteDTO.Cnpj.Replace("-", "").Replace("/", "").Replace(".", "").Replace("_", "").Trim();
                }
                if (clienteDTO.Telefone != null)
                {
                    clienteDTO.Telefone = clienteDTO.Telefone.Replace("_", "").Replace("-", "").Trim();
                }
                if (clienteDTO.Celular != null)
                {
                    clienteDTO.Celular = clienteDTO.Celular.Replace("_", "").Replace("-", "").Trim();
                }

                var Cliente = ClienteFactory.CreateCliente(
                    clienteDTO.NomeFantasia,
                    clienteDTO.RazaoSocial,
                    clienteDTO.Cnpj,
                    clienteDTO.InscricaoEstadual,
                    clienteDTO.Email,
                    clienteDTO.Telefone,
                    clienteDTO.Celular,
                    clienteDTO.Skype,
                    clienteDTO.NomeResponsavel,
                    clienteDTO.Rua,
                    clienteDTO.Numero,
                    clienteDTO.Complemento,
                    clienteDTO.Bairro,
                    clienteDTO.Cidade,
                    clienteDTO.Estado,
                    clienteDTO.Cep,
                    clienteDTO.TipoEmpresa,
                    clienteDTO.MatrizId
                    );

                SalvarCliente(Cliente);

                var adapter = TypeAdapterFactory.CreateAdapter();
                return(adapter.Adapt <Cliente, ClienteDTO>(Cliente));
            }
            catch (Exception ex)
            {
                throw ManipuladorDeExcecao.TrateExcecao(ex);
            }
        }
Ejemplo n.º 3
0
        public ClienteDTO UpdateCliente(ClienteDTO clienteDTO)
        {
            try
            {
                if (clienteDTO == null)
                {
                    throw new ArgumentNullException("clienteDTO");
                }

                var persistido = _clienteRepository.Get(clienteDTO.Id);
                if (persistido == null)
                {
                    throw new Exception("Cliente não encontrado.");
                }

                var corrente = ClienteFactory.CreateCliente(
                    clienteDTO.NomeFantasia,
                    clienteDTO.RazaoSocial,
                    persistido.Cnpj,
                    persistido.InscricaoEstadual,
                    clienteDTO.Email,
                    clienteDTO.Telefone,
                    clienteDTO.Celular,
                    clienteDTO.Skype,
                    clienteDTO.NomeResponsavel,
                    clienteDTO.Rua,
                    clienteDTO.Numero,
                    clienteDTO.Complemento,
                    clienteDTO.Bairro,
                    clienteDTO.Cidade,
                    clienteDTO.Estado,
                    clienteDTO.Cep,
                    persistido.TipoEmpresa,
                    persistido.MatrizId);

                corrente.Id = persistido.Id;

                AlterarCliente(persistido, corrente);

                var adapter = TypeAdapterFactory.CreateAdapter();
                return(adapter.Adapt <Cliente, ClienteDTO>(corrente));
            }
            catch (Exception ex)
            {
                throw ManipuladorDeExcecao.TrateExcecao(ex);
            }
        }