Exemplo n.º 1
0
        public virtual async Task <IActionResult> GetMaterials(GetMaterialsRequest materialsRequest)
        {
            SectionServerCached section = sectionsCache.GetSectionServerCached(materialsRequest.SectionName, User.Roles);

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

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

            if (!("," + sectionData.CategoriesNames + ",").Contains("," + materialsRequest.CategoryName + ","))
            {
                return(BadRequest(
                           $"Can not show {materialsRequest.CategoryName} in {materialsRequest.SectionName} section"));
            }

            CategoryCached category = categoriesCache.GetCategory(materialsRequest.CategoryName);

            if (category == null)
            {
                return(BadRequest($"Can not find {materialsRequest.CategoryName} category"));
            }


            MaterialsShowOptions options = new MaterialsShowOptions
            {
                ShowDeleted = materialsRequest.ShowDeleted,
                CategoryId  = category.Id,
                Page        = materialsRequest.Page,
                Sort        = MaterialsSortOptionsService.MaterialsSortOptions[materialsRequest.Sort]
            };

            using var scope = serviceProvider.CreateScope();
            IMaterialsQueryPresenter materialsQueryPresenter =
                (IMaterialsQueryPresenter)scope.ServiceProvider.GetRequiredService(MaterialsPresenterTypes.GetBySection(section));

            return(await CacheContentAsync(category, category.Id,
                                           () => materialsQueryPresenter.GetMaterialsByCategoryAsync(options), new RequestOptions()
            {
                Sort = materialsRequest.Sort,
                PageNumber = materialsRequest.Page
            }));
        }
Exemplo n.º 2
0
        public virtual async Task <IActionResult> GetMaterialsFromMultiCategories(GetMaterialsRequest materialsRequest)
        {
            SectionServerCached section = sectionsCache.GetSectionServerCached(materialsRequest.SectionName, User.Roles);

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

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

            var сategories = categoriesCache.GetAllCategoriesWithChildren(sectionData.CategoriesNames);

            IList <CategoryCached> categories = authorizationService.GetAllowedCategories(User.Roles,
                                                                                          сategories.Values, operationKeysContainer.MaterialAndCommentsRead);

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

            IEnumerable <int> categoriesIds = categories.Select(x => x.Id).ToArray();

            MaterialsSortOptionsService.MaterialsSortOptions.TryGetValue(materialsRequest.Sort,
                                                                         out Func <IQueryable <Material>, IOrderedQueryable <Material> > sort);

            var options = new MaterialsShowOptions
            {
                CategoriesIds = categoriesIds,
                Page          = materialsRequest.Page,
                PageSize      = sectionData.PageSize,
                Sort          = sort
            };

            using var scope = serviceProvider.CreateScope();
            IMaterialsQueryPresenter materialsQueryPresenter =
                (IMaterialsQueryPresenter)scope.ServiceProvider.GetRequiredService(MaterialsPresenterTypes.GetBySection(section));

            return(await CacheContentAsync(section, categoriesIds,
                                           () => materialsQueryPresenter.GetMaterialsFromMultiCategoryAsync(options), materialsRequest.Page));
        }
Exemplo n.º 3
0
 /// <summary> Setter constructor. </summary>
 public GetMaterials(GetMaterialsRequest request)
 {
     Request  = request;
     Response = new GetMaterialsResponse();
 }
Exemplo n.º 4
0
 /// <summary> Empty constructor. </summary>
 public GetMaterials()
 {
     Request  = new GetMaterialsRequest();
     Response = new GetMaterialsResponse();
 }