示例#1
0
        /// <summary>
        /// Gets all category and non-category item decendents for the provided <see cref="CategoryItem"/>, which should represent a <see cref="Metric"/> or <see cref="MetricCategory"/>.
        /// </summary>
        /// <param name="categoryItem">The <see cref="CategoryItem"/>, which should represent a <see cref="Metric"/> or <see cref="MetricCategory"/>.</param>
        /// <param name="includedCategoryIds">The included category ids.</param>
        /// <param name="metricCategoryService">The <see cref="MetricCategoryService"/>.</param>
        /// <returns></returns>
        private List <CategoryItem> GetAllMetricDescendants(CategoryItem categoryItem, string includedCategoryIds, MetricCategoryService metricCategoryService)
        {
            var childCategories = GetChildren(
                id: categoryItem.Id.AsInteger(),
                rootCategoryId: 0,
                getCategorizedItems: true,
                entityTypeId: EntityTypeCache.Get <MetricCategory>().Id,
                includedCategoryIds: includedCategoryIds
                ).ToList();

            foreach (var childCategory in childCategories)
            {
                if (!childCategory.IsCategory)
                {
                    // Load the MetricCategory.
                    var metricCategory = metricCategoryService.Get(childCategory.Id.AsInteger());
                    if (metricCategory != null)
                    {
                        // Swap the Id to the Metric Id (instead of MetricCategory.Id).
                        childCategory.Id = metricCategory.MetricId.ToString();
                    }
                }

                childCategory.Children = new List <Web.UI.Controls.TreeViewItem>();
                childCategory.Children.AddRange(GetAllMetricDescendants(childCategory, includedCategoryIds, metricCategoryService));
            }

            return(childCategories);
        }
示例#2
0
        public IQueryable <CategoryItem> GetMetricChildren(int id, string includedCategoryIds = "")
        {
            // Get list of categorized MetricCategory objects from GetChildren().
            var metricCategories = GetChildren(
                id: id,
                rootCategoryId: 0,
                getCategorizedItems: true,
                entityTypeId: EntityTypeCache.Get <MetricCategory>().Id,
                includedCategoryIds: includedCategoryIds
                ).ToList();

            var metricCategoryService = new MetricCategoryService(new RockContext());
            var convertedMetrics      = new List <CategoryItem>();

            // Translate from MetricCategory to Metric.
            foreach (var categoryItem in metricCategories)
            {
                if (!categoryItem.IsCategory)
                {
                    // Load the MetricCategory.
                    var metricCategory = metricCategoryService.Get(categoryItem.Id.AsInteger());
                    if (metricCategory != null)
                    {
                        // Swap the Id to the Metric Id (instead of MetricCategory.Id).
                        categoryItem.Id = metricCategory.MetricId.ToString();
                    }
                }

                categoryItem.Children = new List <Web.UI.Controls.TreeViewItem>();
                categoryItem.Children.AddRange(GetAllMetricDescendants(categoryItem, includedCategoryIds, metricCategoryService));

                convertedMetrics.Add(categoryItem);
            }

            return(convertedMetrics.AsQueryable());
        }