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