Ejemplo n.º 1
0
        public FilteredResult(IQueryable <T> items, HttpActionContext actionContext)
            : base(new HttpResponseMessage(System.Net.HttpStatusCode.OK))
        {
            var filters = HeaderUtil.ResolveFilterInfoHeader(actionContext.Request.Headers);

            Items = FilteredResultHelpers.ProcessFilters <T>(items, filters);
            this.Response.Content = new ObjectContent(Items.GetType(), Items, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
        }
Ejemplo n.º 2
0
        public SortedResult(IQueryable <T> items, HttpActionContext actionContext)
            : base(new HttpResponseMessage(System.Net.HttpStatusCode.OK))
        {
            var sort = HeaderUtil.ResolveSortHeader(actionContext.Request.Headers);

            if (!string.IsNullOrEmpty(sort))
            {
                var sortClause = sort.Replace("+", "").Replace("-", " DESC");
                items = items.OrderBy(sortClause);
            }
            this.Items            = items;
            this.Response.Content = new ObjectContent(Items.GetType(), Items, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
        }
Ejemplo n.º 3
0
        public PaginatedResult(IQueryable <T> items, HttpActionContext actionContext)
            : base(new HttpResponseMessage(System.Net.HttpStatusCode.OK))
        {
            PageInfo pageInfo = HeaderUtil.ResolvePageInfoHeaders(actionContext.Request.Headers);

            pageInfo.Total        = pageInfo.Total == 0 ? items.Count() : pageInfo.Total;
            this.Items            = items.Skip((pageInfo.Page - 1) * pageInfo.PageSize).Take(pageInfo.PageSize);
            this.Response.Content = new ObjectContent(this.Items.GetType(), this.Items, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);

            this.Response.Headers.Remove(HeaderValues.KRYPTON_PAGE);
            this.Response.Headers.Add(HeaderValues.KRYPTON_PAGE, pageInfo.Page.ToString());

            this.Response.Headers.Remove(HeaderValues.KRYPTON_TOTAL);
            this.Response.Headers.Add(HeaderValues.KRYPTON_TOTAL, pageInfo.Total.ToString());

            this.Response.Headers.Remove(HeaderValues.KRYPTON_PAGE_SIZE);
            this.Response.Headers.Add(HeaderValues.KRYPTON_PAGE_SIZE, pageInfo.PageSize.ToString());
        }