示例#1
0
        public Task <LazyLoadingDataSetResult <TItem> > GetTablePageData(
            ILazyLoadingOptions lazyLoadingOptions, IPagingOptions pageableOptions, ISortingOptions sortingOptions)
        {
            if (string.IsNullOrWhiteSpace(lazyLoadingOptions.DataUri))
            {
                throw new ArgumentNullException($"When you using {nameof(LazyLoadedTableDataAdapter<TItem>)} you must specify " +
                                                $"{nameof(LazyLoadingOptions.DataUri)} for lazy data retrieving. If you do not want use lazy loading feature use {nameof(CollectionTableDataAdapter<TItem>)} instead.");
            }

            var dataUri = $"{lazyLoadingOptions.DataUri.TrimEnd('/')}?{lazyLoadingOptions.RequestParams}{PagingParams(pageableOptions)}{SortingParams(sortingOptions)}";

            try
            {
                return(httpClient.GetJsonAsync <LazyLoadingDataSetResult <TItem> >(dataUri));
            }
            catch (Exception ex)
            {
                logger.LogError($"Error during fetching data from [{dataUri}]. Ex: {ex}");

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

                return(Task.FromResult(emptyResult));
            }
        }
        public Task <LazyLoadingDataSetResult <TItem> > GetTablePageData(
            RequestOptions requestOptions,
            IReadOnlyCollection <IFilterDefinition> filterDefinitions = null)
        {
            var dataUri = requestOptions.BuildUrl();

            try
            {
                if (filterDefinitions != null && filterDefinitions.Any())
                {
                    return(httpClient.PostJsonAsync <LazyLoadingDataSetResult <TItem> >(dataUri, filterDefinitions));
                }
                else
                {
                    return(httpClient.GetJsonAsync <LazyLoadingDataSetResult <TItem> >(dataUri));
                }
            }
            catch (Exception ex)
            {
                logger.LogError($"Error during fetching data from [{dataUri}]. Ex: {ex}");

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

                return(Task.FromResult(emptyResult));
            }
        }
        public Task <LazyLoadingDataSetResult <TItem> > GetTablePageData(
            ILazyLoadingOptions lazyLoadingOptions, IPagingOptions pageableOptions, ISortingOptions sortingOptions)
        {
            var dataUri = $"{lazyLoadingOptions.DataUri.TrimEnd('/')}?{PagingParams(pageableOptions)}{SortingParams(sortingOptions)}";

            try
            {
                return(httpClient.GetJsonAsync <LazyLoadingDataSetResult <TItem> >(dataUri));
            }
            catch (Exception ex)
            {
                logger.LogError($"Error during fetching data from [{dataUri}]. Ex: {ex}");

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

                return(Task.FromResult(emptyResult));
            }
        }