public IHttpActionResult Index(int?begin = null, int?end = null, int?index = null) { var result = new ViewModels.ListifyFetchResultViewModel { begin = begin, end = end, index = index }; if (!(begin.HasValue && end.HasValue && index.HasValue)) { result.success = false; result.message = "This API requires the following query string parameters to produce a result: begin, end, index. (All integer values. End is exclusive.)"; return(Json(result)); } var list = new Models.Listify(begin.Value, end.Value); result.result = list[index.Value]; result.success = true; return(Json(result)); }
public HttpResponseMessage Get([FromBody] GetListifyValueRequest getValueRequest) { if (getValueRequest == null) return Request.CreateResponse(HttpStatusCode.BadRequest); try { var listify = new Models.Listify(getValueRequest.Begin, getValueRequest.End); var value = listify[getValueRequest.Index]; return Request.CreateResponse(HttpStatusCode.OK, value); } catch (IndexOutOfRangeException e) { var message = $"Index {getValueRequest.Index} not found"; HttpError err = new HttpError(message); return Request.CreateResponse(HttpStatusCode.NotFound, err); } catch (Exception e) { // TODO log and handle under global exception handling return Request.CreateResponse(HttpStatusCode.NotFound, new HttpError("Unhandled error. Please call the administrator.")); } }