public static T[] GridCommonSettingswithCustomFilter <T>(this IQueryable <T> query, GridSettings grid, out int count) { if (grid.IsSearch) { //And if (grid.Where.groupOp == "AND") { foreach (var rule in grid.Where.rules) { if (rule.field != "Pending" && rule.field != "Confirmed") { query = query.Where( rule.field, rule.data, (WhereOperation)StringEnum.Parse(typeof(WhereOperation), rule.op)); } } } else { //Or var temp = query; foreach (var rule in grid.Where.rules) { if (rule.field != "Pending" && rule.field != "Confirmed") { var t = query.Where( rule.field, rule.data, (WhereOperation)StringEnum.Parse(typeof(WhereOperation), rule.op)); temp = temp.Concat(t); } } //remove repeating records query = temp.Distinct(); } } //sorting query = query.OrderBy(grid.SortColumn, grid.SortOrder); //count the total number of count count = query.Count(); // return data with paging return(query.Skip((grid.PageIndex - 1) * grid.PageSize).Take(grid.PageSize).ToArray()); }
public static T[] GridCommonSettings <T>(this IQueryable <T> query, GridSettings grid, out int count) { if (grid.IsSearch) { //And if (grid.Where.groupOp == "AND") { foreach (var rule in grid.Where.rules) { //Hack to resolve datetime issue for equal , add one more where condition with lessthan of next date ParameterExpression parameter = Expression.Parameter(query.ElementType, "p"); MemberExpression memberAccess = null; foreach (var property in rule.field.Split('.')) { memberAccess = MemberExpression.Property (memberAccess ?? (parameter as Expression), property); } if ((memberAccess.Type == typeof(DateTime) || memberAccess.Type == typeof(DateTime?)) && (WhereOperation)StringEnum.Parse(typeof(WhereOperation), rule.op) == WhereOperation.Equal) { query = query.Where( rule.field, rule.data, (WhereOperation)StringEnum.Parse(typeof(WhereOperation), "ge")); query = query.Where( rule.field, DateTime.Parse(rule.data).AddDays(1).Date, (WhereOperation)StringEnum.Parse(typeof(WhereOperation), "lt")); } else { query = query.Where( rule.field, rule.data, (WhereOperation)StringEnum.Parse(typeof(WhereOperation), rule.op)); } } } else { //Or var temp = query; foreach (var rule in grid.Where.rules) { //Hack to resolve datetime issue for equal , add one more where condition with lessthan of next date ParameterExpression parameter = Expression.Parameter(query.ElementType, "p"); MemberExpression memberAccess = null; foreach (var property in rule.field.Split('.')) { memberAccess = MemberExpression.Property (memberAccess ?? (parameter as Expression), property); } if ((memberAccess.Type == typeof(DateTime) || memberAccess.Type == typeof(DateTime?)) && (WhereOperation)StringEnum.Parse(typeof(WhereOperation), rule.op) == WhereOperation.Equal) { var t = query.Where( rule.field, rule.data, (WhereOperation)StringEnum.Parse(typeof(WhereOperation), "ge")); temp = temp.Concat(t); t = query.Where( rule.field, DateTime.Parse(rule.data).AddDays(1).Date, (WhereOperation)StringEnum.Parse(typeof(WhereOperation), "lt")); temp = temp.Concat(t); } else { var t = query.Where( rule.field, rule.data, (WhereOperation)StringEnum.Parse(typeof(WhereOperation), rule.op)); temp = temp.Concat(t); } } //remove repeating records query = temp.Distinct(); } } //sorting query = query.OrderBy(grid.SortColumn, grid.SortOrder); //count the total number of count count = query.Count(); // return data with paging return(query.Skip((grid.PageIndex - 1) * grid.PageSize).Take(grid.PageSize).ToArray()); }