Esempio n. 1
0
        public KryptonListResult(IQueryable <T> items, HttpActionContext actionContext)
            : base(new HttpResponseMessage(System.Net.HttpStatusCode.OK))
        {
            var filterRes = new FilteredResult <T>(items, actionContext);
            var sortRes   = new SortedResult <T>(filterRes.Items, actionContext);
            var pagedRes  = new PaginatedResult <T>(sortRes.Items, actionContext);

            Items = pagedRes.Items;
            foreach (var item in pagedRes.Response.Headers)
            {
                this.Response.Headers.Add(item.Key, item.Value);
            }
            this.Response.Content = new ObjectContent(Items.GetType(), Items, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a KryptonDotNet.KrptonListResult, encapsulates functionality from
 /// FilteredResult, SortedResult, and PaginatedResult
 /// uses -H krypton-page, krypton-page-size, krypton-total, krypton-sort, krypton-filter-info
 /// </summary>
 /// <param name="controller">the current Web Api controller</param>
 /// <param name="items">the list of objects to process</param>
 /// <returns>KryptonDotNet.KrptonListResult</returns>
 public static KryptonListResult <T> KryptonResult <T>(this ApiController controller, IQueryable <T> items)
 {
     try
     {
         var filterRes = new FilteredResult <T>(items, controller.ActionContext);
         var sortRes   = new SortedResult <T>(filterRes.Items, controller.ActionContext);
         var pagedRes  = new PaginatedResult <T>(sortRes.Items, controller.ActionContext);
         return(new KryptonListResult <T>(pagedRes.Response));
     }
     catch (Exception ex)
     {
         //
         return(new KryptonListResult <T>(items, controller.ActionContext));
     }
 }