Beispiel #1
0
        public ClienteDtoReturn Inserir(ClienteInserirViewModel clienteViewModel)
        {
            var cliente = new Cliente(clienteViewModel.Nome, clienteViewModel.Cpf, clienteViewModel.Telefone,
                                      clienteViewModel.DataNascimento, clienteViewModel.Endereco);

            if (!cliente.Valido())
            {
                return(new ClienteDtoReturn(cliente.GetErros()));
            }

            cliente.GerarId();
            _repositorio.Inserir(cliente);

            return(new ClienteDtoReturn(BuscarPorId(cliente.Id)));
        }
Beispiel #2
0
        public HttpResponseMessage Inserir([FromBody] ClienteInserirViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Json inválido"));
            }

            var clienteDtoReturn = _clienteService.Inserir(viewModel);

            if (clienteDtoReturn.Erros.Count > 0)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, clienteDtoReturn.Erros));
            }

            return(Request.CreateResponse(HttpStatusCode.Created, clienteDtoReturn.Cliente));
        }