コード例 #1
0
ファイル: FacetSection.cs プロジェクト: pjbeemster/scratchpad
 public void SetHrefLinks(Query query)
 {
     Location location = new Location(query.getLocation());
     int offset = query.getListStartIndex();
     query.removeListStartIndex();
     int num2 = this.Facets.Count<FacetItem>(f => f.Selected);
     string ticked = HttpContext.Current.Request["fh_ticked"] ?? "";
     foreach (FacetItem item in this.Facets)
     {
         Location location2 = new Location(location);
         MultiValuedCriterion mvc = location2.getCriterion("schematitle") as MultiValuedCriterion;
         if (mvc != null)
         {
             (from f in this.Facets
                 where !f.Enabled
                 select f).ToList<FacetItem>().ForEach(f => mvc.getGreaterThan().remove(f.Value));
             if (string.IsNullOrEmpty(ticked))
             {
                 if (num2 == mvc.getGreaterThan().valueSet().size())
                 {
                     item.Selected = false;
                     mvc.getGreaterThan().clear().add(item.Value);
                 }
             }
             else
             {
                 if (ticked.Split(new char[] { ',' }).Contains<string>(item.Value))
                 {
                     mvc.getGreaterThan().remove(item.Value);
                 }
                 else
                 {
                     mvc.getGreaterThan().add(item.Value);
                 }
                 if (mvc.getGreaterThan().isEmpty())
                 {
                     location2.removeCriteria("schematitle");
                 }
             }
             query.setLocation(location2);
             item.Href = query.ToFhParams();
             if (string.IsNullOrEmpty(ticked))
             {
                 item.Href = item.Href + "&fh_ticked=" + item.Value;
             }
             else
             {
                 List<string> items = ticked.Split(new char[] { ',' }).ToList<string>();
                 (from f in this.Facets
                     where !f.Enabled
                     select f).ToList<FacetItem>().ForEach(f => items.Remove(f.Value));
                 if (items.Contains(item.Value))
                 {
                     items.Remove(item.Value);
                 }
                 else
                 {
                     items.Add(item.Value);
                 }
                 item.Href = Regex.Replace(item.Href, @"&fh_ticked=[\w|,]+", "");
                 if (items.Count > 0)
                 {
                     item.Href = item.Href + "&fh_ticked=" + string.Join(",", items);
                 }
             }
         }
     }
     query.setLocation(location);
     query.setListStartIndex(offset);
     this.Facets.ToList<FacetItem>().ForEach(delegate (FacetItem f) {
         if (f.Enabled)
         {
             f.Selected = false;
         }
         List<string> list = ticked.Split(new char[] { ',' }).ToList<string>();
         if (f.Enabled && list.Contains(f.Value))
         {
             f.Selected = true;
         }
     });
 }
コード例 #2
0
 public static List<FacetPagination> GetFacetPagination(this results r, Query query, int itemsPerPage)
 {
     int num = r.total_items;
     List<FacetPagination> list = new List<FacetPagination>();
     int num2 = num / itemsPerPage;
     num2 += ((num % itemsPerPage) == 0) ? 0 : 1;
     int offset = query.getListStartIndex();
     for (int i = 0; i < num2; i++)
     {
         int num5 = i * itemsPerPage;
         FacetPagination item = new FacetPagination();
         item.LinkText = (i + 1).ToString();
         item.Selected = offset == num5;
         string str = query.setListStartIndex(i * itemsPerPage).toString();
         item.Url = "?fh_params=" + HttpUtility.UrlEncode(str);
         if (!string.IsNullOrEmpty(HttpContext.Current.Request["fh_ticked"]))
         {
             item.Url = item.Url + "&fh_ticked=" + HttpContext.Current.Request["fh_ticked"];
         }
         list.Add(item);
     }
     query.setListStartIndex(offset);
     return list;
 }