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