public IActionResult PutCountry(int continentId, int countryId, [FromBody] CountryInApi countryInApi) { logger.LogInformation($"Post api/continent/{continentId}/country/{countryId} called"); if (countryInApi == null) { return(BadRequest()); } try { if (countryManager.Find(countryId) == null) { Domain.Models.Country country = CountryMapper.CountryInMapper(continentManager, countryInApi); Domain.Models.Country countryCreated = countryManager.AddCountry(country); CountryOutApi countryOut = CountryMapper.CountryOutMapper(hostUrl, countryCreated); return(CreatedAtAction(nameof(GetCountry), new { continentId = countryCreated.Continent.Id, countryId = countryCreated.Id }, countryOut)); } Domain.Models.Country countryUpdate = CountryMapper.CountryInMapper(continentManager, countryInApi); countryManager.UpdateCountry(countryId, countryUpdate, countryUpdate.Continent.Id); return(new NoContentResult()); } catch (Exception ex) { logger.LogError(ex.Message); return(BadRequest(ex.Message)); } }
public ActionResult <CountryInApi> PostCountry(int continentId, [FromBody] CountryInApi countryInApi) { logger.LogInformation($"Post api/continent/{continentId}/country/ called"); try { Domain.Models.Country country = CountryMapper.CountryInMapper(continentManager, countryInApi); Domain.Models.Country countryCreated = countryManager.AddCountry(country); if (countryCreated != null) { CountryOutApi countryOut = CountryMapper.CountryOutMapper(hostUrl, countryCreated); return(CreatedAtAction(nameof(GetCountry), new { continentId = countryCreated.Continent.Id, countryId = countryCreated.Id }, countryOut)); } else { logger.LogError("Country can not be null."); return(NotFound("Country can not be null.")); } } catch (Exception ex) { logger.LogError(ex.Message); return(NotFound(ex.Message)); } }