public List <object> GetList(Type type, RouteData rd) { var clauses = new Dictionary <string, object>(); PagingSpec spec = PagingSpec.Create(rd); if (spec != null) { clauses.Add("@Paging", spec); } return(GetList(type, clauses)); }
public ActionResult FilterCsv(List <string> versionFilter, string[] classFilter, List <ListFilter> filters) { var pagingSpec = PagingSpec.Create(Request.Params); if (filters == null) { filters = new List <ListFilter>(); } string csv = FilterManager.Instance.GenerateCsv(versionFilter, classFilter, filters, pagingSpec); return(File(Encoding.UTF8.GetBytes(csv), "text/csv", "report.csv")); }
/// <summary> /// Gets a paged list of content items filtered by the OData $filter parameters present in the /// request represented by the rd (RouteData) parameter. /// </summary> /// <typeparam name="T">Returned element type of enumerable</typeparam> /// <typeparam name="TQuery">The type in which the $filter parameters are expressed</typeparam> /// <param name="types">The list of content types against which the filter is run</param> /// <param name="rd">The route data of the current request</param> /// <returns>Enumerable of type T of content items filtered and paged</returns> public virtual IEnumerable <T> GetList <T, TQuery>(IEnumerable <Type> types, RouteData rd) where T : class where TQuery : class { var parms = new NameValueCollection(); RequestContextManager.Instance.CurrentContext.Request.Query .Do(kvp => parms.Add(kvp.Key, kvp.Value.FirstOrDefault())); if (rd.DataTokens.ContainsKey("top") && parms["$top"] == null) { parms["$top"] = new StringValues((string)rd.DataTokens["top"]); } if (rd.DataTokens.ContainsKey("orderBy") && parms["$orderBy"] == null) { parms["$orderBy"] = (string)rd.DataTokens["orderBy"]; } if (parms["$orderBy"] != null && typeof(TQuery).GetProperty(parms["$orderBy"]) == null) { parms.Remove("$orderBy"); } Func <IQueryable <TQuery>, IQueryable <TQuery> > queryBody = (iq => iq.Filter(parms).AsFacade <TQuery>()); var parmsCount = new NameValueCollection(parms); parmsCount.Remove("$skip"); parmsCount.Remove("$top"); parmsCount.Remove("$orderBy"); Func <IQueryable <TQuery>, IQueryable <TQuery> > queryBodyCount = (iq => iq.Filter(parmsCount).AsFacade <TQuery>()); var qry = new List <TQuery>().Filter(parmsCount); int count; bool querySummary = typeof(Summary).IsAssignableFrom(typeof(TQuery)); if (querySummary) { count = Get <T, TQuery>(types, queryBodyCount).Count(); } else { count = GetCount <TQuery>(types, queryBodyCount); } var pSpec = PagingSpec.Create(parms); pSpec.Total = count; rd.DataTokens.Add("@Paging", pSpec); return(Get <T, TQuery>(types, queryBody).ToList()); }
public ActionResult FilterItems(List <string> versionFilter, string[] classFilter, List <ListFilter> filters) { var pagingSpec = PagingSpec.Create(Request.Params); if (filters == null) { filters = new List <ListFilter>(); } var pagedResult = FilterManager.Instance.RunFilter(versionFilter, classFilter, filters, pagingSpec); RouteData.DataTokens["@Paging"] = pagingSpec; ViewData["ShowFilts"] = filters.Where(f => f.Show).ToList(); return(PartialView(pagedResult)); }
/// <summary> /// Gets a paged list of content items filtered by the OData $filter parameters present in the /// request represented by the rd (RouteData) parameter. /// </summary> /// <typeparam name="T">Returned element type of enumerable</typeparam> /// <typeparam name="TQuery">The type in which the $filter parameters are expressed</typeparam> /// <param name="types">The list of content types against which the filter is run</param> /// <param name="rd">The route data of the current request</param> /// <returns>Enumerable of type T of content items filtered and paged</returns> public virtual IEnumerable <T> GetList <T, TQuery>(IEnumerable <Type> types, RouteData rd) where T : class where TQuery : class { var parms = new NameValueCollection(HttpContext.Current.Request.Params); if (rd.DataTokens.ContainsKey("top") && parms["$top"] == null) { parms["$top"] = (string)rd.DataTokens["top"]; } if (rd.DataTokens.ContainsKey("orderBy") && parms["$orderBy"] == null) { parms["$orderBy"] = (string)rd.DataTokens["orderBy"]; } Func <IQueryable <TQuery>, IQueryable <TQuery> > queryBody = GetQueryBody <TQuery>(parms); var parmsCount = new NameValueCollection(parms); parmsCount.Remove("$skip"); parmsCount.Remove("$top"); Func <IQueryable <TQuery>, IQueryable <TQuery> > queryBodyCount = GetQueryBody <TQuery>(parmsCount); int count; bool querySummary = typeof(Summary).IsAssignableFrom(typeof(TQuery)); if (querySummary) { count = Get <T, TQuery>(types, queryBodyCount).Count(); } else { count = GetCount <TQuery>(types, queryBodyCount); } var pSpec = PagingSpec.Create(parms); pSpec.Total = count; rd.DataTokens.Add("@Paging", pSpec); return(Get <T, TQuery>(types, queryBody).ToList()); }
//public void AddFilters(Type type, Dictionary<string, object> clauses, RouteData rd) //{ // List<string> specialQueryParams = type.GetProperties().Select(pi => pi.Name).ToList(); // var qb = QueryBuilderFactory.Instance.Create(); // rd.DataTokens // .Where(dt => specialQueryParams.Any(sqp => sqp == dt.Key || dt.Key.StartsWith(sqp + "."))) // .Select(dt => new KeyValuePair<string, object>( //} public List <object> GetList(Type type, RouteData rd) { var clauses = new Dictionary <string, object>(); PagingSpec pagingSpec = PagingSpec.Create(rd); if (pagingSpec != null) { clauses.Add("@Paging", pagingSpec); } FilterSpec filterSpec = FilterSpec.Create(type, rd); if (filterSpec != null) { filterSpec.AddFilterClauses(clauses); } List <object> res = GetList(type, clauses); if (res != null && res.Count > 0 && res[0].GetType() == typeof(PagingSpec)) { rd.DataTokens.Add("@Paging", res[0]); res.RemoveAt(0); } return(res); }