public ActionResult <RCountryOutput> PostCountry([FromBody] RCountryInput input, int continentId) { try { logger.LogInformation(0201, DateTime.Now + "PostCountry called."); if (input == null) { throw new RestException("Het ingegeven land mag niet null zijn"); } if (continentId != input.ContinentId) { throw new RestException("De id in de url en in de body komen niet overeen."); } int countryId = manager.AddCountry(continentId, input.Name, input.Population, input.Surface); return(CreatedAtAction(nameof(GetCountry), new { continentId, countryId }, Mapper.ToRCountryOutput(manager.GetCountry(continentId, countryId), hostURL))); } catch (Exception ex) { logger.LogError(0201, DateTime.Now + "PostCountry failed."); return(BadRequest(ex.Message)); } }
public ActionResult <RCountryOutput> PutCountry(int continentId, int countryId, [FromBody] RCountryInput input) { try { logger.LogInformation(0203, DateTime.Now + "PutCountry called."); if (input == null) { throw new RestException("Er moet een land zijn om te putten."); } if (continentId != input.ContinentId) { throw new RestException("Het id van het continent in de url en in de body komen niet overeen."); } if (countryId != input.Id) { throw new RestException("Het id van het land in de url en in de body komen niet overeen."); } manager.UpdateCountry(countryId, continentId, input.Name, input.Population, input.Surface); return(Ok(Mapper.ToRCountryOutput(manager.GetCountry(continentId, countryId), hostURL))); } catch (Exception ex) { logger.LogError(0203, DateTime.Now + "PutCountry failed."); if (ex.Message == "Er is geen continent met het gegeven id.") { return(NotFound(ex.Message)); } if (ex.Message == "Er is geen land met het gegeven id.") { return(NotFound(ex.Message)); } return(BadRequest(ex.Message)); } }