public static string GetFormattedBreadCrumb(this ArticleGroup category, IArticleService articleService, string separator = ">>") { if (category == null) throw new ArgumentNullException("category"); string result = string.Empty; //used to prevent circular references var alreadyProcessedArticleGroupIds = new List<int>() { }; while (category != null && //not null !category.Deleted && //not deleted !alreadyProcessedArticleGroupIds.Contains(category.Id)) //prevent circular references { if (String.IsNullOrEmpty(result)) { result = category.Name; } else { result = string.Format("{0} {1} {2}", category.Name, separator, result); } alreadyProcessedArticleGroupIds.Add(category.Id); category = articleService.GetArticleGroupById(category.ParentGroupId); } return result; }
public static IList<ArticleGroup> GetArticleGroupBreadCrumb(this ArticleGroup articleGroup, IArticleService articleService, bool showHidden = false) { if (articleGroup == null) throw new ArgumentNullException("articleGroup"); var result = new List<ArticleGroup>(); //used to prevent circular references var alreadyProcessedArticleGroupIds = new List<int>() { }; while (articleGroup != null && //not null !articleGroup.Deleted && //not deleted (showHidden || articleGroup.Published) && //published !alreadyProcessedArticleGroupIds.Contains(articleGroup.Id)) //prevent circular references { result.Add(articleGroup); alreadyProcessedArticleGroupIds.Add(articleGroup.Id); articleGroup = articleService.GetArticleGroupById(articleGroup.ParentGroupId); } result.Reverse(); return result; }