// POST odata/Airports public IHttpActionResult Post(Airport airport) { if (!ModelState.IsValid) { return BadRequest(ModelState); } TripPinSvcDataSource.Instance.Airports.Add(airport); return Created(airport); }
// PUT odata/Airports('key') public IHttpActionResult Put([FromODataUri] string key, Airport airport) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != airport.IcaoCode) { return BadRequest("The IcalCode of Airline does not match the key"); } var oldAirport = TripPinSvcDataSource.Instance.Airports.SingleOrDefault(item => item.IcaoCode == key); if (oldAirport == null) { return NotFound(); } TripPinSvcDataSource.Instance.Airports.Remove(oldAirport); TripPinSvcDataSource.Instance.Airports.Add(airport); return Updated(airport); }