// PUT api/AssociationType/5 public HttpResponseMessage PutAssociationType(Guid id, AssociationType associationtype) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != associationtype.AssociationTypeId) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(associationtype).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/AssociationType public HttpResponseMessage PostAssociationType(AssociationType associationtype) { if (ModelState.IsValid) { db.AssociationTypes.Add(associationtype); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, associationtype); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = associationtype.AssociationTypeId })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }