/// <summary> /// Gets a CSS class name for the tag based on the <see cref="TagSummary.Count"/> - the number of /// pages with that tag in the system. /// </summary> /// <param name="helper">The helper.</param> /// <param name="tag">A <see cref="TagSummary"/>.</param> /// <returns> /// <list type="bullet"> /// <item>1 tag: "tagcloud1"</item> /// <item>1-3 tags: "tagcloud2"</item> /// <item>3-5 tags: "tagcloud3"</item> /// <item>5-10 tags: "tagcloud4"</item> /// <item>10+ tags: "tagcloud5"</item> /// </list> /// </returns> public static string ClassNameForTagSummary(this HtmlHelper helper, TagSummary tag) { string className = ""; if (tag.Count > 10) { className = "tagcloud5"; } else if (tag.Count >= 5 && tag.Count < 10) { className = "tagcloud4"; } else if (tag.Count >= 3 && tag.Count < 5) { className = "tagcloud3"; } else if (tag.Count > 1 && tag.Count < 3) { className = "tagcloud2"; } else if (tag.Count == 1) { className = "tagcloud1"; } return className; }
/// <summary> /// Retrieves a list of all tags in the system. /// </summary> /// <returns>A <see cref="IEnumerable`TagSummary`"/> for the tags.</returns> /// <exception cref="DatabaseException">An NHibernate (database) error occurred while getting the tags.</exception> public IEnumerable<TagSummary> AllTags() { try { var tagList = from p in Pages select new { Tag = p.Tags }; List<TagSummary> tags = new List<TagSummary>(); foreach (var item in tagList) { string[] parts = item.Tag.Split(';'); foreach (string part in parts) { if (!string.IsNullOrEmpty(part)) { string tagName = part.ToLower(); TagSummary summary = new TagSummary(tagName); int index = tags.IndexOf(summary); if (index < 0) { tags.Add(summary); } else { tags[index].Count++; } } } } return tags; } catch (HibernateException ex) { throw new DatabaseException(ex, "An error occurred while retrieving all tags from the database"); } }