public virtual async Task <IActionResult> GetArticles(
            string categoryName, OrderType sort = OrderType.PublishDate, int page = 1, bool showDeleted = false)
        {
            CategoryCached category = categoriesCache.GetCategory(categoryName);

            if (category == null)
            {
                return(BadRequest());
            }

            if (!authorizationService.HasAccess(User.Roles, category, OperationKeys.MaterialAndCommentsRead))
            {
                return(Unauthorized());
            }

            var options = new MaterialsShowOptions
            {
                CategoryId = category.Id,
                orderType  = sort,
                Page       = page,
                PageSize   = articlesOptions.CurrentValue.CategoryPageSize
            };

            if (authorizationService.HasAccess(User.Roles, category, OperationKeys.MaterialHide))
            {
                options.ShowHidden = true;
            }

            if (showDeleted && authorizationService.HasAccess(User.Roles, category, OperationKeys.MaterialDeleteAny))
            {
                options.ShowDeleted = true;
            }


            async Task <IPagedList <ArticleInfoView> > LoadDataAsync()
            {
                return(await articlesPresenter.GetArticlesAsync(options));
            }

            if (showDeleted)
            {
                return(Ok(await LoadDataAsync()));
            }

            return(await CacheContentAsync(category, category.Id, LoadDataAsync, page));
        }
Esempio n. 2
0
        public virtual async Task <IActionResult> GetArticles(string categoryName, ArticlesOrderType sort = ArticlesOrderType.PublishDate, int page = 1)
        {
            CategoryCached category = categoriesCache.GetCategory(categoryName);

            if (category == null)
            {
                return(BadRequest());
            }

            if (!authorizationService.HasAccess(User.Roles, category, OperationKeys.MaterialAndCommentsRead))
            {
                return(Unauthorized());
            }

            async Task <IPagedList <ArticleInfoView> > LoadDataAsync()
            {
                return(await articlesPresenter.GetArticlesAsync(category.Id, sort, page, articlesOptions.CategoryPageSize));
            }

            return(await CacheContentAsync(category, category.Id, LoadDataAsync, page));
        }