public IHttpActionResult PostBooking(Booking booking) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Bookings.Add(booking); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = booking.bookingsId }, booking); }
// PUT api/Booking/5 public IHttpActionResult PutBooking(int id, Booking booking) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != booking.bookingsId) { return BadRequest(); } db.Entry(booking).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookingExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }