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