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);
    }
예제 #2
0
    static IEnumerable <TItem> ApplyToAll <TItem>(this IEnumerable <TItem> items, bool hasId, Func <Type, string, object?> getArguments)
    {
        if (hasId)
        {
            if (ArgumentReader.TryReadIds(getArguments, out var values))
            {
                var predicate = ExpressionBuilder <TItem> .BuildPredicate("Id", Comparison.In, values);

                items = items.Where(predicate.Compile());
            }
        }

        if (ArgumentReader.TryReadWhere(getArguments, out var wheres))
        {
            var predicate = ExpressionBuilder <TItem> .BuildPredicate(wheres);

            items = items.Where(predicate.Compile());
        }

        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);
    }
예제 #3
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);
    }
예제 #4
0
        public static IQueryable <TItem> ApplyGraphQlArguments <TItem>(
            this IQueryable <TItem> queryable,
            IResolveFieldContext context,
            List <string>?keyNames,
            bool applyOrder)
            where TItem : class
        {
            Guard.AgainstNull(nameof(queryable), queryable);
            Guard.AgainstNull(nameof(context), context);
            object?GetArguments(Type type, string x) => context.GetArgument(type, x);

            if (keyNames != null)
            {
                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> .BuildPredicate(keyName, Comparison.Equal, new[] { value });

                    queryable = queryable.Where(predicate);
                }
            }

            if (ArgumentReader.TryReadWhere(GetArguments, out var wheres))
            {
                var predicate = ExpressionBuilder <TItem> .BuildPredicate(wheres);

                queryable = queryable.Where(predicate);
            }

            if (applyOrder)
            {
                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);
        }
예제 #5
0
        static IQueryable <TItem> ApplyToAll <TItem>(this IQueryable <TItem> queryable, Func <Type, string, object?> getArguments, List <string>?keyNames)
            where TItem : class
        {
            if (keyNames != null)
            {
                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> .BuildPredicate(keyName, Comparison.Equal, new[] { value });

                    queryable = queryable.Where(predicate);
                }
            }

            if (ArgumentReader.TryReadWhere(getArguments, out var wheres))
            {
                var predicate = ExpressionBuilder <TItem> .BuildPredicate(wheres);

                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);
        }