public ListingFilters(GetCountsResult counts, string path, string queryString) { var q = WebHelpers.ParseQueryParams(queryString); var sections = new List <Section>(); var totalCount = 0; foreach (var fieldName in counts.CntByValByField.Keys) { var filters = new List <Filter>(); var cntByVal = counts.CntByValByField[fieldName]; foreach (var val in cntByVal.Keys) { totalCount += cntByVal[val]; var f = new Filter { Title = $"{val} ({cntByVal[val]})", Value = val, FieldName = fieldName, Count = cntByVal[val] }; if (q.Contains(fieldName, val)) { f.IsChecked = true; q.Remove(fieldName, val); if (q.Count == 0) { f.OnSubmittedUrl = path; } else { f.OnSubmittedUrl = WebHelpers.AppendParameters("", q.AtomEnumerable); } q.Add(fieldName, val); } else { f.IsChecked = false; q.Add(fieldName, val); f.OnSubmittedUrl = WebHelpers.AppendParameters("", q.AtomEnumerable); q.Remove(fieldName, val); } filters.Add(f); } var section = new Section { SectionName = fieldName, Filters = filters.ToArray(), TotalCount = totalCount }; sections.Add(section); } Sections = sections; }
public static MvcHtmlString SortableHeaderFor <TModelItem, TResult>(this HtmlHelper <IEnumerable <TModelItem> > hh, Expression <Func <TModelItem, TResult> > columnExpression, string currentSortColName = null, string currentSortDir = null, string actionName = null, string overrideDisplayName = null) { currentSortColName = currentSortColName ?? hh.ViewBag.SortCol as string; currentSortDir = currentSortDir ?? hh.ViewBag.SortDir as string; actionName = actionName ?? hh.ViewContext.RouteData.Values["action"] as string; var colName = columnExpression.GetFullyQualifiedName(); var displayName = overrideDisplayName ?? hh.FriendlyNameFor(columnExpression); var d = new RevolutionaryStuff.Core.Collections.MultipleValueDictionary <string, string>(); foreach (var kvp in WebHelpers.ParseQueryParams(hh.ViewContext.HttpContext.Request.Url.Query).AtomEnumerable) { if (kvp.Key == SortColKeyName) { continue; } if (kvp.Key == SortDirKeyName) { continue; } if (null == StringHelpers.TrimOrNull(kvp.Value)) { continue; } d.Add(kvp.Key, kvp.Value); } d.Set(SortColKeyName, colName); if (colName == currentSortColName) { if (IsSortDirAscending(currentSortDir)) { d.Set(SortDirKeyName, SortDirDescending); } var url = WebHelpers.AppendParameters("?", d.AtomEnumerable); var h = hh.AnchorTag(url, displayName); h = h.AppendChildHtml(IsSortDirAscending(currentSortDir) ? " <span class='caret-up'>▲</span>" : " <span class='caret-down'>▼</span>"); return(h); } else { var url = WebHelpers.AppendParameters("?", d.AtomEnumerable); return(hh.AnchorTag(url, displayName)); } }