// POST api/Auctions public HttpResponseMessage PostAuction(Auction auction) { if (ModelState.IsValid) { db.Auctions.Add(auction); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, auction); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = auction.Id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/Auctions/5 public HttpResponseMessage PutAuction(long id, Auction auction) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != auction.Id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(auction).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }