public HttpResponseMessage Get(int id) { var model = repo.getAdministrator(id); if (model == null) { return Request.CreateResponse(HttpStatusCode.NotFound); } else { var view = new AdministratorView(model); return Request.CreateResponse(HttpStatusCode.OK, view); } }
public HttpResponseMessage GetLogin(string email, string password) { var model = repo.getAdministrator(email, password); if (model == null) { return Request.CreateResponse(HttpStatusCode.NotFound); } else { model.authToken = Guid.NewGuid(); repo.update(model); var view = new AdministratorView(model); return Request.CreateResponse(HttpStatusCode.OK, view); } }
public HttpResponseMessage Post(AdministratorView view) { var model = view.getModel(); model.created = DateTime.UtcNow; model.updated = DateTime.UtcNow; model.fakeId = Guid.NewGuid(); model = repo.createAdministrator(model); view = new AdministratorView(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, AdministratorView view) { if (id != view.id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } var model = view.getModel(); model.updated = DateTime.UtcNow; try { repo.update(model); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }