// POST api/events public HttpResponseMessage Post(Event anEvent) { if (ModelState.IsValid) { _db.Add<Event>(anEvent); try { _db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, anEvent); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = anEvent.Id })); return response; } catch (DbUpdateException) { return Request.CreateResponse(HttpStatusCode.InternalServerError); } } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/events/5 public HttpResponseMessage Put(int id, Event anEvent) { if (ModelState.IsValid && id == anEvent.Id) { try { _db.Attach<Event>(anEvent); _db.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK, anEvent); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.Conflict); } } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }