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)); }
public static bool PossuiEnderecoInformado(this ClienteCommand command) { return(AssertionConcern.IsSatisfiedBy( AssertionConcern.AssertTrue(command.Enderecos != null && command.Enderecos.Any(), "Cliente não informou endereço") )); }
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)); }
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); }
public Cliente AddCliente(ClienteCommand command) { Cliente cliente = new Cliente(command); _clienteRepository.AddCliente(cliente); return(cliente); }
public ClienteCommand Cadastrar(ClienteCommand clienteCommand) { var cliente = _clienteService.Adicionar(ClienteAdapter.ToDomainModel(clienteCommand)); if (Commit()) { return(ClienteAdapter.ToModelDomain(cliente)); } return(null); }
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; }
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); }
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); } }
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); } }
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); }
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)); } }
public IActionResult Put([FromRoute] int id, [FromBody] ClienteCommand command) { var cliente = _profissionalWorkflow.UpdateCliente(id, command); return(Ok(cliente)); }
public IActionResult Post([FromBody] ClienteCommand command) { var cliente = _profissionalWorkflow.AddCliente(command); return(Ok(cliente)); }
public async Task <BaseResponse> Create(ClienteCommand command) { return(await _clienteHandler.Handle(command)); }
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."))); }