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