private async Task <IList <Selection <CategoryBase> > > BuildCategories(CategoryTreeOptions options)
        {
            // Get categories
            var categories = await _categoryService
                             .ConfigureQuery(q =>
            {
                // Skip role based security when
                // viewing categories within the admin
                if (IsAdminController())
                {
                    q.UserId.Clear();
                }
            })
                             .GetResultsAsync(options.IndexOptions, new PagerOptions()
            {
                Page = 1,
                Size = int.MaxValue
            });

            return(categories?.Data.Select(c => new Selection <CategoryBase>
            {
                IsSelected = options.SelectedCategories.Any(v => v == c.Id),
                Value = c
            })
                   .ToList());
        }
        private async Task <IList <Selection <CategoryBase> > > BuildCategories(CategoryTreeOptions options)
        {
            // Get categories
            var categories = await _categoryService
                             .GetResultsAsync(options.IndexOptions, new PagerOptions()
            {
                Page = 1,
                Size = int.MaxValue
            });

            return(categories?.Data.Select(c => new Selection <CategoryBase>
            {
                IsSelected = options.SelectedCategories.Any(v => v == c.Id),
                Value = c
            })
                   .ToList());
        }
        public async Task <IViewComponentResult> InvokeAsync(CategoryTreeOptions options)
        {
            if (options == null)
            {
                options = new CategoryTreeOptions();
            }

            if (options.SelectedCategories == null)
            {
                options.SelectedCategories = new int[0];
            }

            return(View(new CategoryTreeViewModel
            {
                HtmlName = options.HtmlName,
                EnableCheckBoxes = options.EnableCheckBoxes,
                EditMenuViewName = options.EditMenuViewName,
                SelectedCategories = await BuildCategories(options),
                CssClass = options.CssClass,
                RouteValues = options.RouteValues
            }));
        }