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