Beispiel #1
0
        private IActionResult processarPost(MotoristaCadastroPostRequest viewModel)
        {
            var carro = viewModel.ToCarroModel();

            _carroService.Add(carro);

            var endereco = viewModel.ToEnderecoModel();

            _enderecoService.Add(endereco);

            var motorista = viewModel.ToMotoristaModel();

            motorista.CarroId    = carro.CarroId;
            motorista.EnderecoId = endereco.EnderecoId;

            _motoristaService.Add(motorista);

            return(Ok("success"));
        }
        public ActionResult <string> Post([FromBody] Carro carro)
        {
            try
            {
                _logger.LogInformation("Received post request");

                if (ModelState.IsValid)
                {
                    _carroService.Add(carro);

                    return(Ok("success"));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, exception.Message);
                return(new StatusCodeResult(500));
            }
        }
Beispiel #3
0
 public Carro Post([FromBody] Carro carro)
 {
     service.Add(carro);
     return(carro);
 }