public async Task <IActionResult> Post([FromBody] CityViewModel city) { // Save to the Database try { var newCity = Mapper.Map <City>(city); _repository.AddCity(newCity); if (await _repository.SaveChangesAsync()) { return(Created($"api/cities/{city.CityName}", Mapper.Map <CityViewModel>(city))); } else { _logger.LogWarning("Could not save city to the database"); } } catch (Exception ex) { _logger.LogError($"Threw exception while saving city: {ex}"); } return(BadRequest("Failed to save the city")); }