示例#1
0
        protected PagingCriteria GetPagingCriteria()
        {
            if (_pagingCriteria != null)
            {
                return(_pagingCriteria);
            }

            string pageNumberString = "0", itemsPerPageString = "0";
            int    pageNumber = 0, itemsPerPage = 0;

            if (Context.Request.QueryString["page"] != null)
            {
                pageNumberString = Context.Request.QueryString["page"];
            }
            else
            if (Context.Request.Headers["X-Page"] != null)
            {
                pageNumberString = Context.Request.Headers["X-Page"];
            }

            if (Context.Request.QueryString["itemsPerPage"] != null)
            {
                itemsPerPageString = Context.Request.QueryString["itemsPerPage"];
            }
            else
            if (Context.Request.Headers["X-Items-Per-Page"] != null)
            {
                itemsPerPageString = Context.Request.Headers["X-Items-Per-Page"];
            }

            if (!int.TryParse(pageNumberString, out pageNumber) || !int.TryParse(itemsPerPageString, out itemsPerPage))
            {
                throw RestNet.ErrorHandler.HttpBadRequest("One or more of the results paging parameters are not valid. 'page' or 'itemsPerPage' in the query string or 'X-Page' or 'X-Items-Per-Page' in the headers are not valid integers.");
            }

            _pagingCriteria = new PagingCriteria(pageNumber, itemsPerPage, 0);

            return(_pagingCriteria);
        }
示例#2
0
 protected void AddResponsePagingHeaders(PagingCriteria pagingCriteria)
 {
     Context.Response.AddHeader("X-Total-Item-Count", pagingCriteria.TotalItems.ToString());
     Context.Response.AddHeader("X-Items-Per-Page", pagingCriteria.ItemsPerPage.ToString());
     Context.Response.AddHeader("X-Page", pagingCriteria.Page.ToString());
 }