public IActionResult RegisterRefuel([FromBody] RegisterRefuelViewModel viewModel) { try { if (ModelState.IsValid) { Vehicle _vehicle = _vehicleService.GetByLicensePlate(viewModel.VehicleLicensePlate); Driver _driver = _driverService.GetByCPF(viewModel.DriverCPF); GasStation _gasStation = _gasStationService.GetByCnpj(viewModel.GasStationCNPJ); Refuel refuel = new Refuel() { TotalValue = viewModel.TotalValue, LiterValue = viewModel.LiterValue, Liters = viewModel.Liters, FuelType = viewModel.FuelType, RefuelDate = viewModel.RefuelDate, Driver = _driver, Vehicle = _vehicle, GasStation = _gasStation }; string _refuelFeedback = refuel.Validate(); if (_refuelFeedback == "ok") { return(Created("", _refuelService.Insert(refuel))); } else { return(BadRequest(_refuelFeedback)); } } else { return(BadRequest()); } } catch (Exception ex) { return(BadRequest(ex.InnerException)); } }