예제 #1
0
        public Task <LazyLoadingDataSetResult <TItem> > GetTablePageData(
            RequestOptions requestOptions,
            IReadOnlyCollection <IFilterDefinition> filterDefinitions = null)
        {
            try
            {
                var queryable  = _queryableSource();
                var totalItems = queryable.Count();
                if (filterDefinitions != null && filterDefinitions.Any())
                {
                    queryable = queryable.Where(_filterExpressionTreeBuilder.BuildExpressionTree(filterDefinitions));
                }
                var items = queryable
                            .ApplySortingToQueryable(requestOptions.SortingOptions)
                            .ApplyPagingToQueryable(requestOptions.PageableOptions)
                            .ToList();
                var result = new LazyLoadingDataSetResult <TItem> {
                    Items = items, TotalCount = totalItems
                };
                return(Task.FromResult(result));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error during fetching data. Ex: {ex}");

                var emptyResult = new LazyLoadingDataSetResult <TItem>
                {
                    Items = Enumerable.Empty <TItem>().ToList()
                };

                return(Task.FromResult(emptyResult));
            }
        }
예제 #2
0
        public Task ApplyFilters(IReadOnlyCollection <IFilterDefinition> filters)
        {
            if (!filters.Any())
            {
                filterExpression = null;
                return(GoToPage(0));
            }

            PageableOptions.CurrentPage = 0;
            filterExpression            = filterExpressionTreeBuilder.BuildExpressionTree(filters);

            return(GoToPage(0));
        }
예제 #3
0
        public Task ApplyFilters(IReadOnlyCollection <IFilterDefinition> filters, bool goToFirstPage = true)
        {
            if (!filters.Any())
            {
                filterExpression = null;
                return(GoToPage(0));
            }

            filterExpression = filterExpressionTreeBuilder.BuildExpressionTree(filters);
            if (goToFirstPage)
            {
                return(GoToPage(0));
            }

            return(Task.CompletedTask);
        }