// POST api/Orders 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.OrderID })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/Orders/5 public HttpResponseMessage PutOrder(int id, Order order) { if (ModelState.IsValid && id == order.OrderID) { 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); } }