Beispiel #1
0
        public static IQueryable <T> OrderBy <T>(IQueryable <T> query, EnumMap <RecommendationsKey, T> map, List <ISort> sorts)
        {
            foreach (var sort in sorts)
            {
                if (!Enum.TryParse(sort.Key, true, out RecommendationsKey key))
                {
                    throw new Exception("Unknown filter key in repository");
                }

                var propertyName = map.Resolve(key);

                query = Order(query, sort, propertyName);
            }

            return(query);
        }
Beispiel #2
0
        public static IQueryable <string> DistinctFieldValues <T>(IQueryable <T> query, EnumMap <RecommendationsKey, T> map, IMultiSelectField field)
        {
            if (!Enum.TryParse(field.Key, true, out RecommendationsKey key))
            {
                throw new Exception("Unknown multi-select key in repository");
            }

            var propertyName = map.Resolve(key);

            Type         t        = typeof(RecommendationProductSummary);
            PropertyInfo property = t.GetProperty(propertyName);

            var resultQuery = query.Select(ds => Convert.ToString(property.GetValue(ds))).Distinct().OrderBy(x => x);

            return(resultQuery);
        }
Beispiel #3
0
        public static IQueryable <RecommendationProductSummary> Filter(IQueryable <RecommendationProductSummary> query, EnumMap <RecommendationsKey, RecommendationProductSummary> map, List <IFilter> filters)
        {
            var operators = new List <OperatorGroup>();

            foreach (var filter in filters)
            {
                if (!Enum.TryParse(filter.Key, true, out RecommendationsKey key))
                {
                    throw new Exception("Unknown filter key in repository");
                }
                var mappedKey = map.Resolve(key);

                operators.Add(BuildOperatorGroup(mappedKey, filter));
            }

            var parameterOfT = Expression.Parameter(typeof(RecommendationProductSummary), "x");

            var expression    = operators.ToExpression(parameterOfT);
            var finalSelector = Expression.Lambda <Func <RecommendationProductSummary, bool> >(expression, parameterOfT);

            return(query.Where(finalSelector));
        }