public async Task <IViewComponentResult> InvokeAsync(CategoryIndexOptions options)
        {
            if (options == null)
            {
                options = new CategoryIndexOptions();
            }

            return(View(await GetIndexModel(options)));
        }
Beispiel #2
0
        public async Task <IPagedResults <TModel> > GetResultsAsync(CategoryIndexOptions options, PagerOptions pager)
        {
            if (options == null)
            {
                options = new CategoryIndexOptions();
            }

            if (pager == null)
            {
                pager = new PagerOptions();
            }

            // Ensure we have a sort column is non is specified
            if (options.Sort == SortBy.Auto)
            {
                options.Sort  = SortBy.SortOrder;
                options.Order = OrderBy.Asc;
            }

            // Get authenticated user
            var user = await _contextFacade.GetAuthenticatedUserAsync();

            // Return tailored results
            return(await _categoryStore.QueryAsync()
                   .Take(pager.Page, pager.Size, pager.CountTotal)
                   .Configure(_configureDb)
                   .Select <CategoryQueryParams>(q =>
            {
                // ----------------
                // Set current authenticated user id
                // This is required for various security checks
                // ----------------

                q.UserId.Equals(user?.Id ?? 0);

                // ----------------
                // Basic parameters
                // ----------------

                // FeatureId
                if (options.FeatureId > 0)
                {
                    q.FeatureId.Equals(options.FeatureId);
                }

                // ----------------
                // Additional parameter configuration
                // ----------------

                _configureParams?.Invoke(q);
            })
                   .OrderBy(options.Sort.ToString(), options.Order)
                   .ToList());
        }
        public Task <IViewComponentResult> InvokeAsync(Category category, CategoryIndexOptions options)
        {
            if (options == null)
            {
                options = new CategoryIndexOptions();
            }

            var model = new CategoryListItemViewModel <Category>()
            {
                Category = category,
                Options  = options
            };

            return(Task.FromResult((IViewComponentResult)View(model)));
        }
        async Task <CategoryListViewModel <Category> > GetIndexModel(CategoryIndexOptions options)
        {
            // Get categories
            var categories = await _categoryService
                             .GetResultsAsync(options, new PagerOptions()
            {
                Page = 1,
                Size = int.MaxValue
            });

            return(new CategoryListViewModel <Category>()
            {
                Options = options,
                Categories = categories?.Data?.Where(c => c.ParentId == options.CategoryId) ?? new List <Category>()
            });
        }
Beispiel #5
0
        public override async Task <IViewProviderResult> BuildIndexAsync(Category categoryAdmin, IViewProviderContext context)
        {
            // Ensure we explicitly set the featureId
            var feature = await _featureFacade.GetFeatureByIdAsync("Plato.Ideas.Categories");

            if (feature == null)
            {
                return(default(IViewProviderResult));
            }


            Category existingCategory = null;

            if (categoryAdmin?.Id > 0)
            {
                existingCategory = await _categoryStore.GetByIdAsync(categoryAdmin.Id);
            }

            // Get topic index view model from context
            var viewModel = context.Controller.HttpContext.Items[typeof(EntityIndexViewModel <Idea>)] as EntityIndexViewModel <Idea>;

            if (viewModel == null)
            {
                throw new Exception($"A view model of type {typeof(EntityIndexViewModel<Idea>).ToString()} has not been registered on the HttpContext!");
            }

            // channel filter options
            var channelViewOpts = new CategoryIndexOptions
            {
                CategoryId = existingCategory?.Id ?? 0,
                FeatureId  = feature.Id
            };

            var indexViewModel = new CategoryIndexViewModel()
            {
                Options            = channelViewOpts,
                EntityIndexOptions = viewModel?.Options,
                Pager = viewModel?.Pager
            };

            return(Views(
                       View <CategoryBase>("Home.Index.Header", model => existingCategory).Zone("header").Order(1),
                       View <CategoryBase>("Home.Index.Tools", model => existingCategory).Zone("tools").Order(1),
                       View <CategoryIndexViewModel>("Home.Index.Content", model => indexViewModel).Zone("content").Order(1),
                       View <CategoryIndexViewModel>("Ideas.Categories.Sidebar", model => indexViewModel).Zone("sidebar").Order(1)
                       ));
        }
        async Task <CategoryListViewModel <Category> > GetIndexModel(CategoryIndexOptions options)
        {
            // Get categories
            var categories = await _categoryService
                             .GetResultsAsync(new CategoryIndexOptions()
            {
                FeatureId  = options.FeatureId,
                CategoryId = 0
            }, new PagerOptions()
            {
                Page = 1,
                Size = int.MaxValue
            });

            return(new CategoryListViewModel <Category>()
            {
                Options = options,
                Categories = categories?.Data
            });
        }
Beispiel #7
0
        async Task <CategoryListViewModel <Category> > GetIndexModel(CategoryIndexOptions options)
        {
            // Get categories
            var categories = await _categoryService
                             .GetResultsAsync(new CategoryIndexOptions()
            {
                FeatureId = options.FeatureId
            },
                                              new PagerOptions()
            {
                Page       = 1,
                Size       = int.MaxValue,
                CountTotal = false
            });

            return(new CategoryListViewModel <Category>()
            {
                Options = options,
                Categories = categories?.Data?.Where(c => c.ParentId == 0)
            });
        }