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