// PUT api/BusinessEntity/5 public HttpResponseMessage PutBusinessEntity(Int32 id, BusinessEntity businessentity) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != businessentity.BusinessEntityId) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(businessentity).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/BusinessEntity public HttpResponseMessage PostBusinessEntity(BusinessEntity businessentity) { if (ModelState.IsValid) { db.BusinessEntities.Add(businessentity); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, businessentity); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = businessentity.BusinessEntityId })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }