예제 #1
0
        public async Task <IActionResult> GetActivities(string materialsCategories, string commentsCategories,
                                                        int number)
        {
            var materialsCategoriesDic = categoriesCache.GetAllCategoriesIncludeSub(materialsCategories);

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


            var commentsCategoriesDic = categoriesCache.GetAllCategoriesIncludeSub(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();

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

            var rez = await activitiesPresenter.GetActivitiesAsync(materialsCategoriesIds, commentsCategoriesIds,
                                                                   number);

            return(Ok(rez));
        }
예제 #2
0
        public virtual async Task <IActionResult> GetPostsFromMultiCategories(string categoriesNames,
                                                                              int page = 1, int?pageSize = null)
        {
            var materialsCategoriesDic = categoriesCache.GetAllCategoriesIncludeSub(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      = pageSize ?? blogOptions.PostsPageSize
            };

            var rez = await blogPresenter.GetPostsFromMultiCategoriesAsync(options);

            return(Json(rez));

            /*async Task<IPagedList<PostViewModel>> LoadDataAsync()
             * {
             * return await blogPresenter.GetPostsFromMultiCategoriesAsync(categoriesIds, page, blogOptions.PostsPageSize);
             * }
             *
             * var blogCategory = categoriesCache.GetCategory(categoriesNames);
             * return await CacheContentAsync(blogCategory, categoriesIds, LoadDataAsync);*/
        }
예제 #3
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.GetAllCategoriesIncludeSub(componentData.materialsCategories);

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


            var commentsCategoriesDic = categoriesCache.GetAllCategoriesIncludeSub(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));
        }
예제 #4
0
        public virtual async Task <IActionResult> GetArticlesFromMultiCategories(string categoriesNames, int page = 1)
        {
            var materialsCategoriesDic = categoriesCache.GetAllCategoriesIncludeSub(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).ToArray();

            IPagedList <ArticleInfoView> articles =
                await articlesPresenter.GetArticlesFromMultiCategoriesAsync(categoriesIds, page, articlesOptions.CategoryPageSize);

            return(Json(articles));
        }
예제 #5
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.GetAllCategoriesIncludeSub(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));
        }