Exemple #1
0
 public virtual void AddSortParam(SortParam param)
 {
     throw new NotSupportedException();
 }
Exemple #2
0
        public static IQueryable <T> ApplyFilters <T>(this IQueryable <T> elementCollection, FilterParam[] filters, SortParam sortParam)
        {
            var result = elementCollection;

            if (filters != null)
            {
                foreach (var filterParam in filters)
                {
                    var         prop  = typeof(T).GetProperty(filterParam.Property);
                    FilterParam param = filterParam;
                    if (prop != null)
                    {
                        switch (filterParam.Expression)
                        {
                        //TODO: implement correct way of Contains/StartWith/EndWith
                        case DaoExpression.Contains:
                            result = ApplyFilter(result, param.Property, ExtendedLinqExpressionType.Contains,
                                                 param.Value);
                            break;

                        case DaoExpression.EndsWith:
                            result = ApplyFilter(result, param.Property, ExtendedLinqExpressionType.EndsWith,
                                                 param.Value);
                            break;

                        case DaoExpression.StartsWith:
                            result = ApplyFilter(result, param.Property, ExtendedLinqExpressionType.StartsWith,
                                                 param.Value);
                            break;

                        case DaoExpression.Eq:
                            result = ApplyFilter(result, param.Property, ExtendedLinqExpressionType.Equal,
                                                 param.Value);
                            break;

                        case DaoExpression.Gt:
                            result = ApplyFilter(result, param.Property, ExtendedLinqExpressionType.GreaterThan,
                                                 param.Value);
                            break;

                        case DaoExpression.GtEq:
                            result = ApplyFilter(result, param.Property,
                                                 ExtendedLinqExpressionType.GreaterThanOrEqual, param.Value);
                            break;

                        case DaoExpression.Lt:
                            result = ApplyFilter(result, param.Property, ExtendedLinqExpressionType.LessThan,
                                                 param.Value);
                            break;

                        case DaoExpression.LtEq:
                            result = ApplyFilter(result, param.Property, ExtendedLinqExpressionType.LessThanOrEqual,
                                                 param.Value);
                            break;

                        case DaoExpression.NotEq:
                            result = ApplyFilter(result, param.Property, ExtendedLinqExpressionType.NotEqual,
                                                 param.Value);
                            break;
                        }
                    }
                }
            }
            if (sortParam != null)
            {
                result = sortParam.Ascending
                             ? result.OrderBy(sortParam.Property)
                             : result.OrderByDescending(sortParam.Property);
            }
            else
            {
                result = result.OrderBy("Id");
            }
            return(result);
        }