// POST api/GCM public HttpResponseMessage PostGCM(GCM gcm) { if (ModelState.IsValid) { gcm.Gcm_created_datetime = DateTime.Now; db.GCMs.Add(gcm); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, gcm.Gcm_id); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = gcm.Gcm_id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/GCM/5 public HttpResponseMessage PutGCM(int id, GCM gcm) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != gcm.Gcm_id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(gcm).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }