// POST api/Rooms public HttpResponseMessage Post(Room room) { if (ModelState.IsValid) { db.Rooms.Add(room); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, room); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = room.id })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/Rooms/5 public HttpResponseMessage Put(int id, Room room) { if (ModelState.IsValid && id == room.id) { db.Rooms.Attach(room); db.Entry(room).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }