// PUT api/Trip/5 public HttpResponseMessage PutTrip(int id, Trip trip) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != trip.ID_TRIP) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(trip).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/Trip public HttpResponseMessage PostTrip(Trip trip) { if (ModelState.IsValid) { db.Trips.Add(trip); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, trip); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = trip.ID_TRIP })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }