public IHttpActionResult PostGuest(Guest guest) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Guest.Add(guest); try { db.SaveChanges(); } catch (DbUpdateException) { if (GuestExists(guest.Guest_No)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = guest.Guest_No }, guest); }
public IHttpActionResult PutGuest(int id, Guest guest) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != guest.Guest_No) { return BadRequest(); } db.Entry(guest).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!GuestExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }