public IHttpActionResult PutTripInPerson([FromODataUri] string key, [FromODataUri] int tripId, Trip trip) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (tripId != trip.TripId) { return BadRequest("The TripId of Trip does not match the tripId."); } var person = TripPinSvcDataSource.Instance.People.SingleOrDefault(item => item.UserName == key); if (person == null) { return NotFound(); } var oldTrip = person.Trips.SingleOrDefault(item => item.TripId == tripId); if (oldTrip == null) { return NotFound(); } person.Trips.Remove(oldTrip); person.Trips.Add(trip); return Updated(trip); }
public IHttpActionResult PostNewTripToPerson([FromODataUri] string key, Trip trip) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var person = TripPinSvcDataSource.Instance.People.SingleOrDefault(item => item.UserName == key); if (person == null) { return NotFound(); } trip.TripId = person.Trips.Max(item => item.TripId) + 1; person.Trips.Add(trip); return Created(trip); }