static IEnumerable <TItem> ApplyToAll <TItem>(this IEnumerable <TItem> items, Func <Type, string, object> getArguments)
    {
        if (ArgumentReader.TryReadId(getArguments, out var values))
        {
            var predicate = FuncBuilder <TItem> .BuildPredicate("Id", Comparison.In, values);

            items = items.Where(predicate);
        }

        foreach (var where in ArgumentReader.ReadWhere(getArguments))
        {
            var predicate = FuncBuilder <TItem> .BuildPredicate(where);

            items = items.Where(predicate);
        }

        items = Order(items, getArguments);

        if (ArgumentReader.TryReadSkip(getArguments, out var skip))
        {
            items = items.Skip(skip);
        }

        if (ArgumentReader.TryReadTake(getArguments, out var take))
        {
            items = items.Take(take);
        }

        return(items);
    }
Example #2
0
    static IQueryable <TItem> ApplyToAll <TItem>(this IQueryable <TItem> queryable, Func <Type, string, object> getArguments)
    {
        if (ArgumentReader.TryReadId(getArguments, out var values))
        {
            var predicate = ExpressionBuilder <TItem> .BuildPredicate("ID", Comparison.In, values);

            queryable = queryable.Where(predicate);
        }

        foreach (var where in ArgumentReader.ReadWhere(getArguments))
        {
            var predicate = ExpressionBuilder <TItem> .BuildPredicate(where);

            queryable = queryable.Where(predicate);
        }

        queryable = Order(queryable, getArguments);

        if (ArgumentReader.TryReadSkip(getArguments, out var skip))
        {
            queryable = queryable.Skip(skip);
        }

        if (ArgumentReader.TryReadTake(getArguments, out var take))
        {
            queryable = queryable.Take(take);
        }

        return(queryable);
    }
        static IQueryable <TItem> ApplyToAll <TItem>(this IQueryable <TItem> queryable, Func <Type, string, object> getArguments, List <string> keyNames)
            where TItem : class
        {
            if (ArgumentReader.TryReadIds(getArguments, out var values))
            {
                var keyName   = GetKeyName(keyNames);
                var predicate = ExpressionBuilder <TItem> .BuildPredicate(keyName, Comparison.In, values);

                queryable = queryable.Where(predicate);
            }

            if (ArgumentReader.TryReadId(getArguments, out var value))
            {
                var keyName   = GetKeyName(keyNames);
                var predicate = ExpressionBuilder <TItem> .BuildSinglePredicate(keyName, Comparison.Equal, value);

                queryable = queryable.Where(predicate);
            }

            foreach (var where in ArgumentReader.ReadWhere(getArguments))
            {
                var predicate = ExpressionBuilder <TItem> .BuildPredicate(where);

                queryable = queryable.Where(predicate);
            }

            queryable = Order(queryable, getArguments);

            if (ArgumentReader.TryReadSkip(getArguments, out var skip))
            {
                queryable = queryable.Skip(skip);
            }

            if (ArgumentReader.TryReadTake(getArguments, out var take))
            {
                queryable = queryable.Take(take);
            }

            return(queryable);
        }