/// <summary> /// Set default <c>Page<c/> number and <c>PageSize<c/> if its not already set in gridifyQuery /// </summary> /// <param name="gridifyQuery">query and paging configuration</param> /// <returns>returns a gridifyQuery with valid PageSize and Page</returns> private static IGridifyQuery FixPagingData(this IGridifyQuery gridifyQuery) { // set default for page number if (gridifyQuery.Page <= 0) { gridifyQuery.Page = 1; } // set default for PageSize if (gridifyQuery.PageSize <= 0) { gridifyQuery.PageSize = DefaultPageSize; } return(gridifyQuery); }
public async static Task <QueryablePaging <T> > GridifyQueryableAsync <T> (this IQueryable <T> query, IGridifyQuery gridifyQuery, IGridifyMapper <T> mapper) { query = query.ApplyFiltering(gridifyQuery, mapper); var count = await query.CountAsync(); query = query.ApplyOrdering(gridifyQuery, mapper); query = query.ApplyPaging(gridifyQuery); return(new QueryablePaging <T> () { TotalItems = count, Query = query }); }
public async static Task <Paging <T> > GridifyAsync <T> (this IQueryable <T> query, IGridifyQuery gridifyQuery, IGridifyMapper <T> mapper = null) { mapper = mapper.FixMapper(); var res = await query.GridifyQueryableAsync(gridifyQuery, mapper); return(new Paging <T> () { Items = await res.Query.ToListAsync(), TotalItems = res.TotalItems }); }
public static async Task <Paging <T> > GridifyAsync <T>(this IQueryable <T> query, IGridifyQuery gridifyQuery, CancellationToken token, IGridifyMapper <T>?mapper = null) { var(count, queryable) = await query.GridifyQueryableAsync(gridifyQuery, mapper, token); return(new Paging <T>(count, await queryable.ToListAsync(token))); }
public static async Task <QueryablePaging <T> > GridifyQueryableAsync <T>(this IQueryable <T> query, IGridifyQuery gridifyQuery, IGridifyMapper <T>?mapper, CancellationToken token) { query = query.ApplyFiltering(gridifyQuery, mapper); var count = await query.CountAsync(token); query = query.ApplyOrdering(gridifyQuery, mapper); query = query.ApplyPaging(gridifyQuery); return(new QueryablePaging <T>(count, query)); }
/// <summary> /// Validates Filter and/or OrderBy with Mappings /// </summary> /// <param name="gridifyQuery">gridify query with (Filter or OrderBy) </param> /// <param name="mapper">the gridify mapper that you want to use with, this is optional</param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static bool IsValid <T>(this IGridifyQuery gridifyQuery, IGridifyMapper <T>?mapper = null) { return(((IGridifyFiltering)gridifyQuery).IsValid(mapper) && ((IGridifyOrdering)gridifyQuery).IsValid(mapper)); }
private static Expression <Func <T, bool> > GetExpressionFromCondition <T> (string condition, IGridifyQuery gridifyQuery, IGridifyMapper <T> mapper) { try { string[] op = { "==", "!=", "=*", "!*", ">>", "<<", ">=", "<=" }; var maps = ParseFilter(condition, op); if (!maps.HasValue) { return(null); } var gMap = mapper.GetGMap(maps.Value.Left); Expression <Func <T, object> > exp = gMap.To; var body = exp.Body; // Remove the boxing for value types if (body.NodeType == ExpressionType.Convert) { body = ((UnaryExpression)body).Operand; } object value = maps.Value.Right; // execute user custom Convertor if (gMap.Convertor != null) { value = gMap.Convertor.Invoke(maps.Value.Right); } if (value != null && body.Type != value.GetType()) { try { // handle broken guids, github issue #2 if (body.Type == typeof(Guid) && !Guid.TryParse(value.ToString(), out _)) { value = Guid.NewGuid(); } var converter = TypeDescriptor.GetConverter(body.Type); value = converter.ConvertFromString(value.ToString()); } catch (System.FormatException) { // return no records in case of any exception in formating return(q => false); } } Expression be = null; var ContainsMethod = typeof(string).GetMethod("Contains", new [] { typeof(string) }); switch (maps.Value.Operation) { case "==": be = Expression.Equal(body, Expression.Constant(value, body.Type)); break; case "!=": be = Expression.NotEqual(body, Expression.Constant(value, body.Type)); break; case ">>": be = Expression.GreaterThan(body, Expression.Constant(value, body.Type)); break; case "<<": be = Expression.LessThan(body, Expression.Constant(value, body.Type)); break; case ">=": be = Expression.GreaterThanOrEqual(body, Expression.Constant(value, body.Type)); break; case "<=": be = Expression.LessThanOrEqual(body, Expression.Constant(value, body.Type)); break; case "=*": be = Expression.Call(body, ContainsMethod, Expression.Constant(value, body.Type)); break; case "!*": be = Expression.Not(Expression.Call(body, ContainsMethod, Expression.Constant(value, body.Type))); break; default: return(null); } return(Expression.Lambda <Func <T, bool> > (be, exp.Parameters)); } catch (Exception) { return(null); } }
private static Expression <Func <T, bool> > GetExpressionFromInternalConditions <T> (IGridifyQuery gridifyQuery, IGridifyMapper <T> mapper, List <(string condition, bool IsAnd)> conditions)