Example #1
0
        protected async Task <ListContext> LoadSectionsAsync()
        {
            var query = Query.Create(ListUI !.PageSize, CurrentState.CurrentPage, CurrentState.SearchTerm, CurrentState.ActiveTab);

            query.CollectionAlias = CurrentState.CollectionAlias;

            if (ListUI.OrderBys != null)
            {
                query.SetOrderBys(ListUI.OrderBys);
            }

            var request = CurrentState.Related != null
                ? (GetEntitiesRequestModel) new GetEntitiesOfRelationRequestModel
            {
                CollectionAlias = CurrentState.CollectionAlias,
                Query           = query,
                Related         = CurrentState.Related,
                UsageType       = CurrentState.UsageType,
                VariantAlias    = CurrentState.VariantAlias
            }
                : (GetEntitiesRequestModel) new GetEntitiesOfParentRequestModel
            {
                CollectionAlias = CurrentState.CollectionAlias,
                ParentPath      = CurrentState.ParentPath,
                Query           = query,
                UsageType       = CurrentState.UsageType,
                VariantAlias    = CurrentState.VariantAlias
            };

            var listContext = await PresentationService.GetEntitiesAsync <GetEntitiesRequestModel, ListContext>(request);

            await SetSectionsAsync(listContext);

            if (!query.MoreDataAvailable)
            {
                CurrentState.MaxPage = CurrentState.CurrentPage;

                if (CurrentState.CurrentPage > 1 && !Sections.Any())
                {
                    CurrentState.CurrentPage--;
                    CurrentState.MaxPage = null;
                    await LoadSectionsAsync();
                }
            }
            if (CurrentState.MaxPage == CurrentState.CurrentPage && query.MoreDataAvailable)
            {
                CurrentState.MaxPage = null;
            }

            return(listContext);
        }
        protected async Task <(ListContext listContext, List <(FormEditContext editContext, IEnumerable <SectionUI> sections)> sections)> LoadSectionsAsync(ListUI listUI, IListUIResolver uiResolver)
        {
            var query = Query.Create(listUI.PageSize, CurrentState.CurrentPage, CurrentState.SearchTerm, CurrentState.ActiveTab);

            query.CollectionAlias = CurrentState.CollectionAlias;

            if (listUI.OrderBys != null)
            {
                query.SetOrderBys(listUI.OrderBys);
            }

            var request = CurrentState.Related != null
                ? (GetEntitiesRequestModel) new GetEntitiesOfRelationRequestModel
            {
                CollectionAlias = CurrentState.CollectionAlias,
                Query           = query,
                Related         = CurrentState.Related,
                UsageType       = CurrentState.UsageType,
                VariantAlias    = CurrentState.VariantAlias
            }
                : (GetEntitiesRequestModel) new GetEntitiesOfParentRequestModel
            {
                CollectionAlias = CurrentState.CollectionAlias,
                ParentPath      = CurrentState.ParentPath,
                Query           = query,
                UsageType       = CurrentState.UsageType,
                VariantAlias    = CurrentState.VariantAlias
            };

            var listContext = await PresentationService.GetEntitiesAsync <GetEntitiesRequestModel, ListContext>(request);

            var sections = await listContext.EditContexts.ToListAsync(async editContext => (editContext, await uiResolver.GetSectionsForEditContextAsync(editContext)));

            if (!query.MoreDataAvailable)
            {
                CurrentState.MaxPage = CurrentState.CurrentPage;

                if (CurrentState.CurrentPage > 1 && sections?.Any() != true)
                {
                    CurrentState.CurrentPage--;
                    CurrentState.MaxPage = null;
                    return(await LoadSectionsAsync(listUI, uiResolver));
                }
            }
            if (CurrentState.MaxPage == CurrentState.CurrentPage && query.MoreDataAvailable)
            {
                CurrentState.MaxPage = null;
            }

            return(listContext, sections);
        }