예제 #1
0
        public async Task <IEnumerable <IPage> > GetChildPagesAsync(IPageCollectionReference pageCollectionReference, int offset, int limit)
        {
            var pageService = ViewContext.HttpContext.RequestServices.GetRequiredService <IPageService>();

            if (pageCollectionReference.CollectionId == Guid.Empty)
            {
                return(new IPage[0]);
            }

            var options = new GetPagesOptions(pageCollectionReference.CollectionId);

            if (offset >= 0 && limit > 0)
            {
                options.Pagination = new PagePaginationOptions(offset, limit);
            }

            var accessProvider = ViewContext.HttpContext.RequestServices.GetRequiredService <Identity.IAccessProvider>();

            if (await accessProvider.CheckAccessAsync())
            {
                options.IncludeDrafts = true;
            }

            var pages = await pageService.GetPagesAsync(options);

            return(pages);
        }
예제 #2
0
        public async Task <IEnumerable <IPage> > GetPagesAsync(GetPagesOptions options, CancellationToken cancellationToken = default)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var collection = await pageCollectionRepositiry.FindCollectiondByIdAsync(options.CollectionId);

            if (collection == null)
            {
                throw new InvalidOperationException();
            }

            if (!options.SortDirection.HasValue)
            {
                options.SortDirection = collection.SortMode;
            }

            if (!options.CustomSorting.HasValue)
            {
                options.CustomSorting = collection.CustomSorting;
            }

            return(await pageRepositiry.GetPagesAsync(options, cancellationToken));
        }
예제 #3
0
        public async Task <IEnumerable <IPage> > GetPagesAsync(GetPagesOptions options, CancellationToken cancellationToken = default)
        {
            var filters = new List <FilterDefinition <PageDocument> >
            {
                Builders <PageDocument> .Filter.Eq(it => it.OwnCollectionId, options.CollectionId)
            };

            if (!options.IncludeDrafts)
            {
                filters.Add(Builders <PageDocument> .Filter.Eq(it => it.Status, PageStatus.Published));
            }

            var findDefinition = pageDocuments.Find(Builders <PageDocument> .Filter.And(filters));
            var sortDirection  = options.SortDirection ?? PageSortMode.FirstOld;

            if (options.CustomSorting.HasValue && options.CustomSorting.Value)
            {
                findDefinition = findDefinition.SortBy(it => it.Order);
            }
            else
            {
                switch (sortDirection)
                {
                case PageSortMode.FirstOld:
                    findDefinition = findDefinition.SortBy(it => it.CreatedDate);
                    break;

                case PageSortMode.FirstNew:
                    findDefinition = findDefinition.SortByDescending(it => it.CreatedDate);
                    break;

                default:
                    throw new ArgumentException("Недопустимый тип сортировки.");
                }
            }

            if (options.Pagination != null)
            {
                findDefinition = findDefinition
                                 .Skip(options.Pagination.Skip)
                                 .Limit(options.Pagination.Limit);
            }

            var cursor = await findDefinition.ToCursorAsync(cancellationToken);

            return(cursor.ToEnumerable(cancellationToken));
        }
예제 #4
0
        public Task <IEnumerable <IPage> > GetPagesAsync(GetPagesOptions options, CancellationToken cancellationToken = default)
        {
            var pages = pageHierarhy.OnGetPages(options.CollectionId);

            return(Task.FromResult(pages));
        }