Esempio n. 1
0
        public static async Task <IEnumerable <TSource> > GetObjectResponseAsync <TSource>(this IQueryable <TSource> data, DataTablesParam param)
        {
            var filters          = new DataTablesFiltering();
            var outputProperties = DataTablesTypeInfo <TSource> .Properties;
            var filteredData     = filters.ApplyFiltersAndSort(param, data, outputProperties);
            var queryResult      = await filteredData.ToListAsync();

            return(queryResult);
        }
Esempio n. 2
0
        public static async Task <DataTablesResponseData> GetDataTableResponseAsync <TSource>(this IQueryable <TSource> data, DataTablesParam param, Action <TSource> postQueryTransform, bool disablePaging = false)
        {
            var filters          = new DataTablesFiltering();
            var outputProperties = DataTablesTypeInfo <TSource> .Properties;

            List <TSource> queryResult;
            var            totalDisplayRecords = 0;
            var            filteredData        = filters.ApplyFiltersAndSort(param, data, outputProperties);

            if (!disablePaging)
            {
                totalDisplayRecords = await filteredData.CountAsync();

                var skipped = filteredData.Skip(param.iDisplayStart);
                queryResult = await(param.iDisplayLength <= 0 ? skipped : skipped.Take(param.iDisplayLength)).ToListAsync();
            }
            else
            {
                queryResult = await filteredData.ToListAsync();

                totalDisplayRecords = queryResult.Count();
            }

            queryResult.ForEach(postQueryTransform);

            var result = new DataTablesResponseData()
            {
                iTotalRecords        = totalDisplayRecords,
                iTotalDisplayRecords = totalDisplayRecords,
                sEcho  = param.sEcho,
                aaData = queryResult.Cast <object>().ToArray(),
            };

            var responseOptions = new ResponseOptions <TSource> {
                ArrayOutputType = null
            };
            var dictionaryTransform = DataTablesTypeInfo <TSource> .ToDictionary(responseOptions);

            result = result.Transform(dictionaryTransform).Transform <Dictionary <string, object>, Dictionary <string, object> >(StringTransformers.StringifyValues);
            result = ApplyOutputRules(result, responseOptions);
            return(result);
        }