public KendoDataSourceResponse(IQueryable <TEntity> queryable, KendoDataSourceRequest request, IMapper mapper = null)
        {
            SetModelMappings(mapper);

            // Filter the data first
            queryable = ApplyFilter(queryable, request.FilterWrapper);

            // Calculate the total number of records (needed for paging)
            this.Total = queryable.Count();

            // Calculate the aggregates
            //var aggregates = Aggregates(queryable, aggregates);

            // Add sort for grouped fields
            if (request.Groups != null && request.Groups.Any())
            {
                if (request.Sorts == null)
                {
                    request.Sorts = new List <SortDescriptor>();
                }

                foreach (var source in request.Groups.Reverse())
                {
                    request.Sorts.Append(new SortDescriptor
                    {
                        Field = source.Field,
                        Dir   = source.Dir
                    });
                }
            }

            // Sort the data
            queryable = ApplySort(queryable, request.Sorts);

            // Finally page the data
            if (request.PageSize > 0)
            {
                queryable = ApplyPaging(queryable, request.Page, request.PageSize);
            }

            // Group By
            if (request.Groups != null && request.Groups.Any())
            {
                this.Groups = ApplyGrouping(queryable, request.Groups);
            }
            else
            {
                if (mapper != null && typeof(TEntity) != typeof(TDto))
                {
                    this.Data = mapper.ProjectTo <TDto>(queryable).ToList();
                }
                else
                {
                    this.Data = queryable.ToList();
                }
            }
        }
Beispiel #2
0
 public static KendoDataSourceResponse <T, T> ToDataSourceResult <T>(this IQueryable <T> queryable, KendoDataSourceRequest request)
 {
     return(new KendoDataSourceResponse <T, T>(queryable, request, null));
 }
Beispiel #3
0
 public static KendoDataSourceResponse <T, TDto> ToDataSourceResult <T, TDto>(this IQueryable <T> queryable, KendoDataSourceRequest request, IMapper mapper = null)
 {
     return(new KendoDataSourceResponse <T, TDto>(queryable, request, mapper));
 }