Beispiel #1
0
        public async Task <HttpResponseMessage> Get(string contextId = null, string lineItemId = null, string id = null, int?limit = null, string firstPage = null, int?p = null)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    // Get a paginated list of results from a ResultContainer

                    int page = 1;
                    if (p.HasValue)
                    {
                        if (firstPage != null && p.Value != 1)
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                               new ArgumentException("Request cannot specify both firstPage and a page number > 1")));
                        }
                        page = p.Value;
                    }
                    var context = new GetResultsContext(contextId, lineItemId, limit, page);

                    await OnGetResults(context);

                    return(context.StatusCode == HttpStatusCode.OK
                        ? Request.CreateResponse(context.StatusCode, context.ResultContainerPage, new ResultContainerPageFormatter())
                        : Request.CreateResponse(context.StatusCode));
                }
                else
                {
                    // Get a representation of a particular LisResult instance

                    var context = new GetResultContext(contextId, lineItemId, id);

                    await OnGetResult(context);

                    return(context.StatusCode == HttpStatusCode.OK
                        ? Request.CreateResponse(context.StatusCode, context.Result, new ResultFormatter())
                        : Request.CreateResponse(context.StatusCode));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
        public async Task<HttpResponseMessage> Get(string contextId = null, string lineItemId = null, string id = null, int? limit = null, string firstPage = null, int? p = null)
        {
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    // Get a paginated list of results from a ResultContainer

                    int page = 1;
                    if (p.HasValue)
                    {
                        if (firstPage != null && p.Value != 1)
                        {
                            return Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                new ArgumentException("Request cannot specify both firstPage and a page number > 1"));
                        }
                        page = p.Value;
                    }
                    var context = new GetResultsContext(contextId, lineItemId, limit, page);

                    await OnGetResults(context);

                    return context.StatusCode == HttpStatusCode.OK
                        ? Request.CreateResponse(context.StatusCode, context.ResultContainerPage, new ResultContainerPageFormatter())
                        : Request.CreateResponse(context.StatusCode);
                }
                else
                {
                    // Get a representation of a particular LisResult instance

                    var context = new GetResultContext(contextId, lineItemId, id);

                    await OnGetResult(context);

                    return context.StatusCode == HttpStatusCode.OK
                        ? Request.CreateResponse(context.StatusCode, context.Result, new ResultFormatter())
                        : Request.CreateResponse(context.StatusCode);
                }
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }
        }