コード例 #1
0
        public async Task <IActionResult> GetActivities(string sectionName)
        {
            var section = SectionsCache.GetSectionServerCached(sectionName, User.Roles);

            if (section == null)
            {
                return(BadRequest($"No component {sectionName} found in cache"));
            }

            ActivitiesServerSection sectionData = section.GetData <ActivitiesServerSection>();

            var materialsCategoriesDic =
                categoriesCache.GetAllCategoriesWithChildren(sectionData.MaterialsCategories);
            var materialsCategoriesExcludeDic =
                categoriesCache.GetAllCategoriesWithChildren(sectionData.MaterialsCategoriesExclude);

            foreach (var(key, _) in materialsCategoriesExcludeDic)
            {
                materialsCategoriesDic.Remove(key);
            }

            IList <CategoryCached> materialsCategoriesList = authorizationService.GetAllowedCategories(User.Roles,
                                                                                                       materialsCategoriesDic.Values, OperationKeys.MaterialAndCommentsRead);

            var commentsCategoriesDic        = categoriesCache.GetAllCategoriesWithChildren(sectionData.CommentsCategories);
            var commentsCategoriesExcludeDic = categoriesCache.GetAllCategoriesWithChildren(sectionData.CommentsCategoriesExclude);

            foreach (var(key, _) in commentsCategoriesExcludeDic)
            {
                commentsCategoriesDic.Remove(key);
            }

            IList <CategoryCached> commentsCategoriesList = authorizationService.GetAllowedCategories(User.Roles,
                                                                                                      commentsCategoriesDic.Values, OperationKeys.MaterialAndCommentsRead);


            int[] materialsCategoriesIds = materialsCategoriesList.Select(x => x.Id).ToArray();
            int[] commentsCategoriesIds  = commentsCategoriesList.Select(x => x.Id).ToArray();

            int number = sectionData.Number;

            if (number > MaxActivitiesInQuery)
            {
                number = MaxActivitiesInQuery;
            }

            async Task <ActivityView[]> LoadDataAsync()
            {
                return(await activitiesPresenter.GetActivitiesAsync(materialsCategoriesIds, commentsCategoriesIds,
                                                                    number));
            }

            return(await CacheContentAsync(
                       section,
                       materialsCategoriesIds.Union(commentsCategoriesIds),
                       LoadDataAsync));
        }
コード例 #2
0
        public async Task <IActionResult> GetActivities(string componentName)
        {
            var component = componentsCache.GetComponentServerCached(componentName, User.Roles);

            if (component == null)
            {
                return(BadRequest($"No component {componentName} found in cache"));
            }

            ActivitiesComponentData componentData = component.Data as ActivitiesComponentData;

            var materialsCategoriesDic =
                categoriesCache.GetAllCategoriesWithChildren(componentData.MaterialsCategories);

            IList <CategoryCached> materialsCategoriesList = authorizationService.GetAllowedCategories(User.Roles,
                                                                                                       materialsCategoriesDic.Values, OperationKeys.MaterialAndCommentsRead);


            var commentsCategoriesDic = categoriesCache.GetAllCategoriesWithChildren(componentData.CommentsCategories);

            IList <CategoryCached> commentsCategoriesList = authorizationService.GetAllowedCategories(User.Roles,
                                                                                                      commentsCategoriesDic.Values, OperationKeys.MaterialAndCommentsRead);


            int[] materialsCategoriesIds = materialsCategoriesList.Select(x => x.Id).ToArray();
            int[] commentsCategoriesIds  = commentsCategoriesList.Select(x => x.Id).ToArray();

            int number = componentData.Number;

            if (number > MaxActivitiesInQuery)
            {
                number = MaxActivitiesInQuery;
            }

            async Task <ActivityView[]> LoadDataAsync()
            {
                return(await activitiesPresenter.GetActivitiesAsync(materialsCategoriesIds, commentsCategoriesIds,
                                                                    number));
            }

            return(await CacheContentAsync(
                       component,
                       materialsCategoriesIds.Union(commentsCategoriesIds),
                       LoadDataAsync));
        }
コード例 #3
0
        public virtual async Task <IActionResult> GetPostsFromMultiCategories(string sectionName, int page = 1)
        {
            var section = sectionsCache.GetSectionserverCached(sectionName, User.Roles);

            if (section == null)
            {
                return(BadRequest($"No component {sectionName} found in cache"));
            }

            PostsServerSectionData sectionData = (PostsServerSectionData)section.Data;

            var materialsCategoriesDic        = categoriesCache.GetAllCategoriesWithChildren(sectionData.Categories);
            var materialsCategoriesExcludeDic =
                categoriesCache.GetAllCategoriesWithChildren(sectionData.CategoriesExclude);

            foreach (var(key, _) in materialsCategoriesExcludeDic)
            {
                materialsCategoriesDic.Remove(key);
            }

            var categoriesList = authorizationService.GetAllowedCategories(User.Roles,
                                                                           materialsCategoriesDic.Values, OperationKeys.MaterialAndCommentsRead);

            if (categoriesList.Count == 0)
            {
                return(BadRequest("No categories to show"));
            }

            var categoriesIds = categoriesList.Select(x => x.Id);

            var options = new MaterialsMultiCatShowOptions
            {
                CategoriesIds = categoriesList.Select(x => x.Id),
                Page          = page,
                PageSize      = sectionData.PageSize,
                PreviewSize   = sectionData.PreviewSize
            };

            return(await CacheContentAsync(section, categoriesIds, LoadDataAsync, page));

            async Task <IPagedList <PostView> > LoadDataAsync() =>
            await blogPresenter.GetPostsFromMultiCategoriesAsync(options);
        }
コード例 #4
0
        public virtual async Task <IActionResult> GetPostsFromMultiCategories(string componentName, int page = 1)
        {
            var component = componentsCache.GetComponentServerCached(componentName, User.Roles);

            if (component == null)
            {
                return(BadRequest($"No component {componentName} found in cache"));
            }

            PostsComponentData componentData = component.Data as PostsComponentData;

            var materialsCategoriesDic = categoriesCache.GetAllCategoriesWithChildren(componentData.CategoriesNames);

            IList <CategoryCached> categoriesList = authorizationService.GetAllowedCategories(User.Roles,
                                                                                              materialsCategoriesDic.Values, OperationKeys.MaterialAndCommentsRead);

            if (categoriesList.Count == 0)
            {
                return(BadRequest("No categories to show"));
            }

            var categoriesIds = categoriesList.Select(x => x.Id);

            var options = new MaterialsMultiCatShowOptions
            {
                CategoriesIds = categoriesList.Select(x => x.Id),
                Page          = page,
                PageSize      = componentData.PageSize,
                PreviewSize   = componentData.PreviewSize
            };

            async Task <IPagedList <PostView> > LoadDataAsync()
            {
                return(await blogPresenter.GetPostsFromMultiCategoriesAsync(options));
            }

            return(await CacheContentAsync(component, categoriesIds, LoadDataAsync, page));
        }
コード例 #5
0
        public virtual async Task <IActionResult> GetArticlesFromMultiCategories(string categoriesNames, int page = 1)
        {
            var materialsCategoriesDic = categoriesCache.GetAllCategoriesWithChildren(categoriesNames);

            IList <CategoryCached> categoriesList = authorizationService.GetAllowedCategories(User.Roles,
                                                                                              materialsCategoriesDic.Values, OperationKeys.MaterialAndCommentsRead);

            if (categoriesList.Count == 0)
            {
                return(BadRequest("No categories to show"));
            }

            var options = new MaterialsMultiCatShowOptions
            {
                CategoriesIds = categoriesList.Select(x => x.Id),
                Page          = page,
                PageSize      = articlesOptions.CurrentValue.CategoryPageSize
            };

            IPagedList <ArticleInfoView> articles = await articlesPresenter.GetArticlesFromMultiCategoriesAsync(options);

            return(Json(articles));
        }