// POST api/ModelInfoAPI public HttpResponseMessage PostModel(Model model) { if (ModelState.IsValid) { db.Models.Add(model); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, model); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = model.ModelId })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/ModelInfoAPI/5 public HttpResponseMessage PutModel(int id, Model model) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != model.ModelId) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(model).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }