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