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