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