public IHttpActionResult PostRoom(Room room) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Rooms.Add(room); try { db.SaveChanges(); } catch (DbUpdateException) { if (RoomExists(room.Room_No)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = room.Room_No }, room); }
public IHttpActionResult PutRoom(int id, Room room) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != room.Room_No) { return BadRequest(); } db.Entry(room).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RoomExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }