public async Task <ActionResult <Cliente> > Put(long id, [FromBody]  ClienteCommand cliente)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var existe = await db.Cliente.AnyAsync(c => c.Id == id);

            if (!existe)
            {
                return(BadRequest("Cliente não encontrado na base"));
            }

            db.Cliente.Update(_mapper.Map <Cliente>(cliente));

            await db.SaveChangesAsync();

            var result = await db.Cliente.FindAsync(id);

            if (result == null)
            {
                return(BadRequest());
            }

            return(Ok(result));
        }
예제 #2
0
 public static bool PossuiEnderecoInformado(this ClienteCommand command)
 {
     return(AssertionConcern.IsSatisfiedBy(
                AssertionConcern.AssertTrue(command.Enderecos != null && command.Enderecos.Any(),
                                            "Cliente não informou endereço")
                ));
 }
예제 #3
0
        public Task <HttpResponseMessage> Put(Guid id, [FromBody] dynamic body)
        {
            //Entradas de dados devem ser revistas quando for criado o Frontend

            var clienteCommand = new ClienteCommand(
                nome: (string)body.nome,
                cpf: (string)body.cpf,
                celular: (string)body.celular,
                email: (string)body.email,
                dataDeNascimento: (DateTime?)body.dataDeNascimento,
                imagem: (string)body.imagem
                );
            var enderecoCommand = new EnderecoCommand(
                logradouro: (string)body.endereco.logradouro,
                numero: (string)body.endereco.numero,
                complemento: (string)body.endereco.complemento,
                bairro: (string)body.endereco.bairro,
                cep: (string)body.endereco.cep,
                idCidade: (Guid)body.endereco.cidadeId,
                idEstado: (Guid)body.endereco.estadoId
                );

            clienteCommand.Endereco = enderecoCommand;
            clienteCommand.IdPessoa = id;

            var cliente = _clienteApp.Atualizar(clienteCommand);

            return(CreateResponse(HttpStatusCode.OK, cliente));
        }
예제 #4
0
        public ClienteCommand Atualizar(ClienteCommand clienteCommand)
        {
            var cliente = _clienteService.ObterPorId(clienteCommand.IdPessoa.Value);

            cliente.AtualizarDados(clienteCommand.Nome, clienteCommand.CPF, clienteCommand.Celular,
                                   clienteCommand.Email, clienteCommand.DataDeNascimento.Value);

            var clienteRetorno = _clienteService.Atualizar(cliente);

            var endereco = _enderecoService.ObterEnderecoPorIdPessoa(clienteCommand.IdPessoa.Value);

            endereco.AtualizarDados(clienteCommand.Endereco.Logradouro, clienteCommand.Endereco.Numero, clienteCommand.Endereco.Complemento,
                                    clienteCommand.Endereco.Bairro, clienteCommand.Endereco.CidadeId, clienteCommand.Endereco.EstadoId,
                                    clienteCommand.Endereco.Cep);

            var enderecoRetorno = _enderecoService.Atualizar(endereco);

            clienteRetorno.AdicionarEndereco(enderecoRetorno);

            if (Commit())
            {
                return(ClienteAdapter.ToModelDomain(clienteRetorno));
            }

            return(null);
        }
예제 #5
0
        public Cliente AddCliente(ClienteCommand command)
        {
            Cliente cliente = new Cliente(command);

            _clienteRepository.AddCliente(cliente);

            return(cliente);
        }
예제 #6
0
        public ClienteCommand Cadastrar(ClienteCommand clienteCommand)
        {
            var cliente = _clienteService.Adicionar(ClienteAdapter.ToDomainModel(clienteCommand));

            if (Commit())
            {
                return(ClienteAdapter.ToModelDomain(cliente));
            }

            return(null);
        }
예제 #7
0
파일: Cliente.cs 프로젝트: tdias8/Mec
 public void Update(ClienteCommand command)
 {
     Nome           = command.Nome;
     Email          = command.Email;
     Telefone       = command.Telefone;
     Endereco       = command.Endereco;
     Cpf            = command.Cpf;
     DataNascimento = command.DataNascimento;
     Sexo           = command.Sexo;
     EstadoCivil    = command.EstadoCivil;
     Ativo          = command.Ativo;
 }
예제 #8
0
        public Cliente UpdateCliente(int id, ClienteCommand command)
        {
            Cliente cliente = _clienteRepository.GetCliente(id);

            if (cliente != null)
            {
                cliente.Update(command);
                _clienteRepository.UpdateCliente(cliente);
                return(cliente);
            }

            return(null);
        }
예제 #9
0
        private bool ValidateDocumentoCadastroNacional(ClienteCommand command)
        {
            if (command.DocumentoCadastroNacional == null)
            {
                return(true);
            }

            if (command.Tipo == ClienteTipoEnum.PessoaFisica)
            {
                return(command.DocumentoCadastroNacional.Length == 11);
            }
            else
            {
                return(command.DocumentoCadastroNacional.Length == 14);
            }
        }
예제 #10
0
        private bool ValidateDocumentoCadastroEstadual(ClienteCommand command)
        {
            if (command.DocumentoCadastroEstadual == null)
            {
                return(true);
            }

            var length = command.DocumentoCadastroEstadual.Length;

            if (command.Tipo == ClienteTipoEnum.PessoaFisica)
            {
                return(length <= 12);
            }
            else
            {
                return(length > 12 && length <= 14);
            }
        }
예제 #11
0
        public static Cliente ToDomainModel(ClienteCommand clienteCommand)
        {
            var cliente = new Cliente(
                clienteCommand.DataDeNascimento,
                clienteCommand.Nome,
                clienteCommand.CPF,
                clienteCommand.Celular,
                clienteCommand.IdPessoa,
                clienteCommand.Imagem);

            if (!string.IsNullOrEmpty(clienteCommand.Email))
            {
                cliente.DefinirEmail(clienteCommand.Email);
            }

            cliente.AdicionarEndereco(EnderecoAdapter.ToDomainModel(clienteCommand.Endereco));

            return(cliente);
        }
예제 #12
0
        public static ClienteCommand ToModelDomain(Cliente cliente)
        {
            if (cliente == null)
            {
                return(null);
            }

            var clienteCommand = new ClienteCommand(
                cliente.Nome,
                cliente.CPF.Codigo,
                cliente.Celular.Numero,
                cliente.Email.Endereco,
                cliente.DataDeNascimento,
                ImageHelper.ConverterParaBase64String(cliente.Imagem));

            clienteCommand.IdPessoa = cliente.IdPessoa;
            clienteCommand.Endereco = EnderecoAdapter.ToModelDomain(cliente.ListaDeEnderecos.FirstOrDefault());

            return(clienteCommand);
        }
        public async Task <ActionResult <ClienteViewModel> > Post([FromBody] ClienteCommand cliente)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }

                await db.Cliente.AddAsync(_mapper.Map <Cliente>(cliente));

                await db.SaveChangesAsync();

                return(Ok(cliente));
            }
            catch (System.Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
예제 #14
0
        public IActionResult Put([FromRoute] int id, [FromBody] ClienteCommand command)
        {
            var cliente = _profissionalWorkflow.UpdateCliente(id, command);

            return(Ok(cliente));
        }
예제 #15
0
        public IActionResult Post([FromBody] ClienteCommand command)
        {
            var cliente = _profissionalWorkflow.AddCliente(command);

            return(Ok(cliente));
        }
예제 #16
0
 public async Task <BaseResponse> Create(ClienteCommand command)
 {
     return(await _clienteHandler.Handle(command));
 }
예제 #17
0
 public static bool EhMaiorDeIdade(this ClienteCommand command)
 {
     return(command.DataNascimento == null || AssertionConcern.IsSatisfiedBy(
                AssertionConcern.AssertTrue(DateTime.Now.Year - command.DataNascimento.Value.Year >= 18,
                                            "Cliente não tem maioridade para cadastro.")));
 }