public ActionResult <RContinentOutput> PutContinent(int id, [FromBody] RContinentInput input) { try { logger.LogInformation(0103, DateTime.Now + "PutContinent called."); if (input == null) { throw new RestException("Het ingegeven continent mag niet null zijn"); } if (id != input.Id) { throw new RestException("De id in de url en in de body komen niet overeen."); } manager.UpdateContinent(id, Mapper.ToContinent(input)); return(Ok(Mapper.ToRContinentOutput(manager.GetContinent(id), hostURL))); } catch (Exception ex) { logger.LogError(0103, DateTime.Now + "PutContinent failed."); if (ex.Message == "Er is geen continent met het gegeven id.") { return(NotFound(ex.Message)); } return(BadRequest(ex.Message)); } }
public ActionResult <RContinentOutput> PostContinent([FromBody] RContinentInput input) { try { logger.LogInformation(0101, DateTime.Now + "PostContinent called."); if (input == null) { throw new RestException("Het ingegeven continent mag niet null zijn"); } int id = manager.AddContinent(Mapper.ToContinent(input)); return(CreatedAtAction(nameof(GetContinent), new { id }, Mapper.ToRContinentOutput(manager.GetContinent(id), hostURL))); } catch (Exception ex) { logger.LogError(0101, DateTime.Now + "PostContinent failed."); return(BadRequest(ex.Message)); } }