// POST api/DocType public HttpResponseMessage PostDocType(DocType doctype) { if (ModelState.IsValid) { db.DocTypes.Add(doctype); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, doctype); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = doctype.ID })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/DocType/5 public HttpResponseMessage PutDocType(int id, DocType doctype) { if (ModelState.IsValid && id == doctype.ID) { db.Entry(doctype).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }