예제 #1
0
        /// <summary>
        /// Executes the filter as defined by the supplied definition
        /// </summary>
        /// <param name="searchDefinition">Search definition</param>
        /// <returns></returns>
        public IEnumerable <T> Filter(SearchDefinition <T> searchDefinition)
        {
            // Sanitize the input
            if (searchDefinition == null)
            {
                searchDefinition = new SearchDefinition <T>();
            }

            // Pre-filter
            var prePredicate = this.CreateWherePredicate(searchDefinition.PreFilter?.Criteria);

            if (prePredicate != null)
            {
                _preParams   = new Dictionary <string, object>(_whereParams);
                _whereParams = new Dictionary <string, object>();
                object[] parameters = _preParams.Values.ToArray();
                _dataSet = _dataSet.Where(prePredicate, parameters);
            }

            // Filter
            var wherePredicate = this.CreateWherePredicate(searchDefinition.Filter?.Criteria);

            if (wherePredicate != null)
            {
                object[] parameters = _whereParams.Values.ToArray();
                _dataSet = _dataSet.Where(wherePredicate, parameters);
            }

            return(_dataSet.AsEnumerable <T>());
        }
예제 #2
0
        /// <summary>
        /// Execute the search as defined by the supplied definition
        /// </summary>
        /// <param name="searchDefinition">Search definition</param>
        /// <returns></returns>
        public SearchResult <T> Search(SearchDefinition <T> searchDefinition)
        {
            // Sanitize the input
            if (searchDefinition == null)
            {
                searchDefinition = new SearchDefinition <T>();
            }
            var page           = searchDefinition.Page;
            var recordsPerPage = searchDefinition.RecordsPerPage;

            // Pre-filter
            var prePredicate = this.CreateWherePredicate(searchDefinition.PreFilter?.Criteria);

            if (prePredicate != null)
            {
                _preParams   = new Dictionary <string, object>(_whereParams);
                _whereParams = new Dictionary <string, object>();
                object[] parameters = _preParams.Values.ToArray();
                _dataSet = _dataSet.Where(prePredicate, parameters);
            }

            int totalRecordCount = _dataSet.Count();

            // Filter
            var wherePredicate = this.CreateWherePredicate(searchDefinition.Filter?.Criteria);

            if (wherePredicate != null)
            {
                object[] parameters = _whereParams.Values.ToArray();
                _dataSet = _dataSet.Where(wherePredicate, parameters);
            }

            int filteredRecordCount = _dataSet.Count();

            if (filteredRecordCount > 0)
            {
                // Sort
                var sortPredicate = this.CreateSortPredicate(searchDefinition.Sort?.Criteria);
                if (sortPredicate != null)
                {
                    _dataSet = _dataSet.OrderBy(sortPredicate);
                }

                //Page
                if (page.HasValue && recordsPerPage.HasValue)
                {
                    _dataSet = this.Page(page.Value, recordsPerPage.Value);
                }
            }

            return(new SearchResult <T>()
            {
                Page = page,
                RecordsPerPage = recordsPerPage,
                ResultSet = _dataSet.ToList(),
                TotalRecordCount = totalRecordCount,
                FilteredRecordCount = filteredRecordCount
            });
        }