// POST api/Flowers public HttpResponseMessage PostFlower(Flower flower) { try { db.Flowers.Add(flower); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, flower); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = flower.Id })); return response; } catch (Exception e) { return Request.CreateResponse(HttpStatusCode.NotAcceptable); } }
// PUT api/Flowers/5 public HttpResponseMessage PutFlower(int id, Flower flower) { if ( id == flower.Id) { db.Entry(flower).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }