Пример #1
0
        /// <summary>
        /// Gets and returns ResponseOfT VW_BASELINE_DATA for Kendo grid. Supports
        /// server side paging, sorting and filtering.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public List <object> BuildPredicateQueryColumnFilter(Dictionary <string, object> request, List <TestViewModel> data = null)
        {
            TestViewModel dataObj = new TestViewModel();

            // Build query
            string whereClause = BusinessLogicHelper.GetWhereCondition(request);

            // get filterParams from request
            object filterParam;
            bool   ableToParseFilterParam = request.TryGetValue("workspaceFilters", out filterParam);

            // get columnFilter from request
            object columnFilter;
            bool   columnFilterProvided = request.TryGetValue("columnFilter", out columnFilter);

            // Begin queryable GET
            var queryableResults = data != null?data.AsQueryable() : _dbContext.TestViewModels.AsQueryable();

            //Apply Filter parameters
            if (ableToParseFilterParam && filterParam != null)
            {
                var param = JObject.Parse(filterParam.ToString()).ToObject <FilterParams>();
                if (param != null)
                {
                    queryableResults = dataObj.ApplyFilterParams(queryableResults, param);
                }
            }
            else
            {
                queryableResults = queryableResults.Select(y => y).Where(x => (int)x.Id == -1);
            }

            //apply grid options/grid filters
            queryableResults = queryableResults.Where(whereClause);

            // ensure column filter is provided
            if (!columnFilterProvided)
            {
                throw new Exception("Bad request: No column filter provided.");
            }

            var columnFilterStr = columnFilter.ToString().Replace("\"", "");

            // get result
            IEnumerable <string> results = dataObj.SelectColumnFilterLinq <TestViewModel, string>(queryableResults, columnFilterStr).Distinct().OrderBy(x => x).AsEnumerable();

            return(dataObj.ConvertColumnFilterObjects(columnFilterStr, results));
        }