Exemplo n.º 1
0
        public IQueryable <Conversation> ApplyFilter(IQueryable <Conversation> conversations, Filter filter)
        {
            var expression = _filterExpressionFactory.Create(filter);

            conversations = conversations.Where(expression);
            return(conversations);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Parses the passes query parameters to a <see cref="ModelFilter{T}" />.
        /// </summary>
        /// <param name="queryParameters"></param>
        /// <returns></returns>
        public IModelFilter <T> Parse(NameValueCollection queryParameters)
        {
            var orderbyField     = queryParameters[StringConstants.OrderByParameter];
            var selects          = queryParameters[StringConstants.SelectParameter];
            var filter           = queryParameters[StringConstants.FilterParameter];
            var skip             = queryParameters[StringConstants.SkipParameter];
            var top              = queryParameters[StringConstants.TopParameter];
            var inlineCount      = queryParameters[StringConstants.InlineCount];
            var includeCount     = !string.IsNullOrWhiteSpace(inlineCount) || inlineCount == "allpages";
            var filterExpression = _filterExpressionFactory.Create <T>(filter);
            var sortDescriptions = _sortExpressionFactory.Create <T>(orderbyField);
            var selectFunction   = _selectExpressionFactory.Create(selects);

            return(new ModelFilter <T>(filterExpression, selectFunction, sortDescriptions,
                                       string.IsNullOrWhiteSpace(skip) ? -1 : Convert.ToInt32(skip),
                                       string.IsNullOrWhiteSpace(top) ? -1 : Convert.ToInt32(top), includeCount));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parses the passes query parameters to a <see cref="ModelFilter{T}"/>.
        /// </summary>
        /// <param name="queryParameters"></param>
        /// <returns></returns>
        public IModelFilter <T> Parse(NameValueCollection queryParameters)
        {
            var orderbyField = queryParameters[StringConstants.OrderByParameter];
            var selects      = queryParameters[StringConstants.SelectParameter];
            var filter       = queryParameters[StringConstants.FilterParameter];
            var skip         = queryParameters[StringConstants.SkipParameter];
            var top          = queryParameters[StringConstants.TopParameter];

            var filterExpression = m_filterExpressionFactory.Create <T>(filter);
            var sortDescriptions = m_sortExpressionFactory.Create <T>(orderbyField);
            var selectFunction   = m_selectExpressionFactory.Create(selects);

            var modelFilter = new ModelFilter <T>(
                filterExpression,
                selectFunction,
                sortDescriptions,
                skip.IsNullOrWhiteSpace() ? -1 : Convert.ToInt32(skip),
                top.IsNullOrWhiteSpace() ? -1 : Convert.ToInt32(top));

            return(modelFilter);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Parses the passes query parameters to a <see cref="ModelFilter{T}"/>.
        /// </summary>
        /// <param name="queryParameters"></param>
        /// <returns></returns>
        public IModelFilter <T> Parse(IEnumerable <KeyValuePair <string, string> > queryParameters)
        {
            var orderbyField = queryParameters.GetValue(StringConstants.OrderByParameter).FirstOrDefault();
            var selects      = queryParameters.GetValue(StringConstants.SelectParameter).FirstOrDefault();
            var filter       = queryParameters.GetValue(StringConstants.FilterParameter).FirstOrDefault();
            var skip         = queryParameters.GetValue(StringConstants.SkipParameter).FirstOrDefault();
            var top          = queryParameters.GetValue(StringConstants.TopParameter).FirstOrDefault();

            var filterExpression = _filterExpressionFactory.Create <T>(filter);
            var sortDescriptions = _sortExpressionFactory.Create <T>(orderbyField);
            var selectFunction   = _selectExpressionFactory.Create(selects);

            var modelFilter = new ModelFilter <T>(
                _settings,
                filterExpression,
                selectFunction,
                sortDescriptions,
                string.IsNullOrWhiteSpace(skip) ? -1 : Convert.ToInt32(skip),
                string.IsNullOrWhiteSpace(top) ? -1 : Convert.ToInt32(top));

            return(modelFilter);
        }