// PUT api/RelationType/5 public HttpResponseMessage PutRelationType(byte id, RelationType relationtype) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != relationtype.RelationTypeId) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(relationtype).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/RelationType public HttpResponseMessage PostRelationType(RelationType relationtype) { if (ModelState.IsValid) { db.RelationTypes.Add(relationtype); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, relationtype); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = relationtype.RelationTypeId })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }