public IActionResult Put(VehicleViewModel model, int id) { try { if (ModelState.IsValid) { var oldVehicle = _repository.GetVehicleById(id); if (oldVehicle == null) { return(NotFound($"Could not find the vehicle at ID: {id} to update.")); } _mapper.Map(model, oldVehicle); _repository.SaveAll(); return(Ok(_mapper.Map <Vehicle, VehicleViewModel>(oldVehicle))); } else { return(BadRequest("Model state is not valid.")); } } catch (Exception e) { return(BadRequest($"There was an error attempting to update the vehicle: {e}")); } }