// PUT api/Notes/5 public HttpResponseMessage PutNotes(Int32 id, Note notes) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != notes.Id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(notes).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/Notes public HttpResponseMessage PostNotes(Note notes) { if (ModelState.IsValid) { db.Notes.Add(notes); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, notes); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = notes.Id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }