public HttpResponseMessage Get(int id) { var model = repo.getText(id); if (model == null) { return Request.CreateResponse(HttpStatusCode.NotFound); } else { var view = new TextView(model); return Request.CreateResponse(HttpStatusCode.OK, view); } }
public HttpResponseMessage Post(TextView view) { var model = view.getModel(); model.created = DateTime.UtcNow; model = repo.createText(model); view = new TextView(model); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, view); response.Headers.Location = new Uri(Url.Link("ApiControllerAndId", new { id = view.id })); return response; }
public HttpResponseMessage Put(int id, TextView view) { if (id != view.id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } var model = view.getModel(); try { repo.update(model); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }