// PUT api/Invoices/5 public HttpResponseMessage Put(int id, Invoice invoice) { if (ModelState.IsValid && id == invoice.id) { db.Invoices.Attach(invoice); db.Entry(invoice).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// POST api/Invoices public HttpResponseMessage Post(Invoice invoice) { if (ModelState.IsValid) { db.Invoices.Add(invoice); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, invoice); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = invoice.id })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }