// POST api/Order public HttpResponseMessage PostOrder(Order order) { if (ModelState.IsValid) { db.Orders.Add(order); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, order); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = order.Id })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/Order/5 public HttpResponseMessage PutOrder(long id, Order order) { if (ModelState.IsValid && id == order.Id) { db.Entry(order).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }