예제 #1
0
        public static DataSourceResult GetDataSourceResult <TModel, TResult>(this IQueryable <TModel> modelQueryableInstances, DataSourceRequest request, Func <TModel, TResult> mapper)
        {
            DataSourceResult dataSourceResult = null;

            if (request.Filters.Any())
            {
                var dataSourceBasedOnViewModelFields = request.RefineDataSource(typeof(TResult));
                if (dataSourceBasedOnViewModelFields.Any())
                {
                    //modelQueryableInstances.WhereV<TResult>(dataSourceBasedOnViewModelFields);
                    dataSourceResult       = modelQueryableInstances.ToDataSourceResult <TModel, TResult>(request, mapper);
                    dataSourceResult.Data  = (IQueryable)dataSourceResult.Data.AsQueryable().Where(dataSourceBasedOnViewModelFields);
                    dataSourceResult.Total = dataSourceResult.Data.AsQueryable().Count();
                }
                else // if filter contains not any items.
                {
                    dataSourceResult = modelQueryableInstances.ToDataSourceResult <TModel, TResult>(request, mapper);
                    //return dataSourceResult;
                }
                return(dataSourceResult);
            }
            else // if filter contains not any items.
            {
                dataSourceResult = modelQueryableInstances.ToDataSourceResult <TModel, TResult>(request, mapper);
                return(dataSourceResult);
            }
        }