// PUT api/Item/5 public HttpResponseMessage PuterItem(int id, erItem eritem) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != eritem.Id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(eritem).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/Item public HttpResponseMessage PosterItem(erItem eritem) { if (ModelState.IsValid) { db.Items.Add(eritem); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, eritem); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = eritem.Id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }