public static void GridParams(out int take, out int skip, out int page, out int pageSize, out string OrderByField, out string OrderByType, out List <KendoFilter> filters, HttpRequestBase Request) { take = int.Parse(Request.Params["take"]); skip = int.Parse(Request.Params["skip"]); page = int.Parse(Request.Params["page"]); pageSize = int.Parse(Request.Params["pageSize"]); OrderByField = !String.IsNullOrEmpty(Request.Params["sort[0][field]"]) ? Request.Params["sort[0][field]"] : ""; OrderByType = !String.IsNullOrEmpty(Request.Params["sort[0][dir]"]) ? Request.Params["sort[0][dir]"] : ""; var localFilters = new List <KendoFilter>(); foreach (var filterName in Request.Params) { if (Regex.IsMatch(filterName.ToString(), @"filter\[filters\]\[\d\]\[value\]")) { Match match = Regex.Match(filterName.ToString(), @"(\d)"); var i = int.Parse(match.Groups[0].Value); var filter = new KendoFilter(); filter.Name = Request.Params[$"filter[filters][{i}][field]"]; filter.Operator = Request.Params[$"filter[filters][{i}][operator]"]; filter.Value = Request.Params[$"filter[filters][{i}][value]"]; localFilters.Add(filter); } } filters = localFilters; }
/// <summary> /// Преобразует экземпляр CallsRequest в XElement для передачи в запросах /// </summary> /// <param name="obj">Экземпляр CallsRequest</param> /// <returns>XElement с данными CallsRequest</returns> static public XElement ToXElement(CallsRequest obj) { var xml = new XElement("Request"); xml.Add(new XElement("sessionKey", obj.SessionKey)); xml.Add(new XElement("page", obj.Page)); xml.Add(new XElement("pageSize", obj.PageSize)); xml.Add(new XElement("searchTerm", obj.SearchTerm)); KendoFilter.AddRequestFilters(ref xml, obj.Filters); return(xml); }
public JsonResult GetCalls(long?page, long?pageSize, KendoFilter filter = null, string searchTerm = "") { var requestParameters = new CallsRequest() { SessionKey = session.Key, Page = page.HasValue ? page.Value : 0, PageSize = pageSize.HasValue ? pageSize.Value : 0, SearchTerm = searchTerm, Filters = filter }; var response = WebHostCache.Current.GetResponse <XElement>(@"api\CallRegistry\GetCalls", CallsRequest.ToXElement(requestParameters), WebHostCache.ContentTypes.xml); var result = CallDTO.ArrayFromXElement(response).ViewModelList(); return(Json(new { rc = 0, Items = result, Total = response.Element("Total").getValue(Int32.MinValue) }, JsonRequestBehavior.AllowGet)); }
private bool TryGetFilter(ModelBindingContext bindingContext, string prefix, out KendoFilter filter) { if (TryGetFilterLogic(bindingContext, prefix, out var logic)) { var filters = new List <KendoFilter>(); var filterIndex = 0; while (true) { if (!TryGetFilter(bindingContext, $"{prefix}[filters][{filterIndex}]", out var subFilter)) { break; } filters.Add(subFilter); filterIndex++; } filter = new KendoFilter { Logic = logic, Filters = filters }; return(true); } if (TryGetFilterField(bindingContext, prefix, out var field) && TryGetFilterValue(bindingContext, prefix, out var value)) { filter = new KendoFilter { Field = field, Operation = TryGetFilterOperation(bindingContext, prefix, out var operation) ? operation : null, Value = value }; return(true); } filter = null; return(false); }
//public PagedResult<CourseDto> Get([FromQuery]FilterRequest request) public async Task <PagedResult <CourseDto> > Get([DataSourceRequest] DataSourceRequest request) { var filter = new KendoFilter(request); return(await _service.Get(filter)); }
private static SystemExpression ToExpression(ParameterExpression parameter, KendoFilter filter) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } if (filter.Filters != null) { if (filter.Filters.Count() < 2) { throw new ArgumentOutOfRangeException(nameof(filter.Filters), filter.Filters, "Number of Filters must be at least 2."); } switch (filter.Logic) { case "or": return(OrElseExpression(parameter, filter.Filters)); case "and": case null: return(AndAlsoExpression(parameter, filter.Filters)); default: throw new ArgumentOutOfRangeException(nameof(filter.Logic), filter.Logic, "Logic not supported."); } } switch (filter.Operation) { case "eq": case null: return(EqualExpression(parameter, filter.Field, filter.Value)); case "neq": return(NotEqualExpression(parameter, filter.Field, filter.Value)); case "lt": return(LessThanExpression(parameter, filter.Field, filter.Value)); case "lte": return(LessThanOrEqualExpression(parameter, filter.Field, filter.Value)); case "gt": return(GreaterThanExpression(parameter, filter.Field, filter.Value)); case "gte": return(GreaterThanOrEqualExpression(parameter, filter.Field, filter.Value)); case "startswith": return(StartsWithExpression(parameter, filter.Field, filter.Value)); case "endswith": return(EndsWithExpression(parameter, filter.Field, filter.Value)); case "contains": return(ContainsExpression(parameter, filter.Field, filter.Value)); case "doesnotcontain": return(NotContainsExpression(parameter, filter.Field, filter.Value)); default: throw new ArgumentOutOfRangeException(nameof(filter.Operation), filter.Operation, "Operator not supported."); } }
public static async Task <string> BuildWhereClauseAsync <T>(int index, string logic, KendoFilter filter, List <object> parameters) { var entityType = (typeof(T)); var property = entityType.GetProperty(filter.Field); var relFieldName = filter.Field; switch (filter.Operator.ToLower()) { case "eq": case "neq": case "gte": case "gt": case "lte": case "lt": if (typeof(DateTime).IsAssignableFrom(property.PropertyType)) { parameters.Add(DateTime.Parse(filter.Value).Date); return(string.Format("EntityFunctions.TruncateTime({0}){1}@{2}", filter.Field, ToLinqOperator(filter.Operator), index)); } if (typeof(int).IsAssignableFrom(property.PropertyType)) { parameters.Add(int.Parse(filter.Value)); return(string.Format("{0}{1}@{2}", filter.Field, ToLinqOperator(filter.Operator), index)); } parameters.Add(filter.Value); return(string.Format("{0}{1}@{2}", relFieldName, ToLinqOperator(filter.Operator), index)); case "startswith": parameters.Add(filter.Value); return(string.Format("{0}.StartsWith(" + "@{1})", relFieldName, index)); case "endswith": parameters.Add(filter.Value); return(string.Format("{0}.EndsWith(" + "@{1})", relFieldName, index)); case "contains": parameters.Add(filter.Value); return(string.Format("{0}.Contains(" + "@{1})", relFieldName, index)); default: throw new ArgumentException( "This operator is not yet supported for this Grid", filter.Operator); } }