// POST api/Producers public HttpResponseMessage PostProducer(Producer producer) { if (ModelState.IsValid) { db.Producers.Add(producer); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, producer); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = producer.ProducerId })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/Producers/5 public HttpResponseMessage PutProducer(int id, Producer producer) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != producer.ProducerId) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(producer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }