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)); }
public virtual Task <IPagedList <ArticleInfoView> > GetArticlesAsync(int categoryId, ArticlesOrderType order, int page, int pageSize) { Func <IQueryable <Material>, IOrderedQueryable <Material> > orderBy; if (order == ArticlesOrderType.PublishDate) { orderBy = x => x.OrderByDescending(y => y.PublishDate); } else { orderBy = x => x.OrderByDescending(y => y.SortNumber); } return(db.MaterialsNotDeleted.GetPagedListAsync( x => new ArticleInfoView { Id = x.Id, Name = x.Name, Title = x.Title, Description = x.Description, CommentsCount = x.CommentsCount, AuthorName = x.Author.UserName, PublishDate = x.PublishDate, CategoryName = x.Category.NameNormalized }, x => x.CategoryId == categoryId, orderBy, page, pageSize)); }