protected override async Task OnInitializedAsync() { ProjectViewModels = await ProjectDataService.GetProjectsAsync(); //Not a fan of this nested logic //What I'm trying to do is collect every distinct category of a given type of CategoryTypeFilter foreach (ProjectViewModel projectVM in ProjectViewModels) { foreach (Category category in projectVM.Categories) { if (!CategoryList.Contains <Category>(category) && category.Type == CategoryTypeFilter) { CategoryList.Add(category); } } } }
/// <summary> /// Filters out content references to content that does not match current category filters, if any /// </summary> /// <param name="contentReferences"></param> /// <returns></returns> private IList <T> FilterByCategory <T>(IEnumerable <T> contentReferences) { if (_category == null || !_category.Any()) { return(contentReferences.ToList()); } // Filter by category if a category filter has been set var filteredChildren = new List <T>(); foreach (var contentReference in contentReferences) { ICategorizable content = null; if (contentReference is ContentReference) { content = (contentReference as ContentReference).Get <IContent>() as ICategorizable; } else if (typeof(T) == typeof(GetChildrenReferenceResult)) { content = (contentReference as GetChildrenReferenceResult).ContentLink.Get <IContent>() as ICategorizable; } if (content != null) { var atLeastOneMatchingCategory = content.Category.Any(c => _category.Contains(c)); if (atLeastOneMatchingCategory) { filteredChildren.Add(contentReference); } } else // Non-categorizable content will also be included { filteredChildren.Add(contentReference); } } return(filteredChildren); }
public bool ContainsCategory(String category) { return(CategoryList.Contains(category)); }