Ejemplo n.º 1
0
        /// <summary>Gets the filter associated with the specified key from the context.</summary>
        /// <param name="key">The filter key associated to the filter.</param>
        /// <returns>The filter associated with the specified key from the context.</returns>
        public static AliasBaseQueryFilter Filter(object key)
        {
            AliasBaseQueryFilter filter;

            GlobalFilters.TryGetValue(key, out filter);

            return(filter);
        }
        /// <summary>
        ///     Creates and return a filter associated with the specified key added for the context.
        /// </summary>
        /// <typeparam name="T">The type of elements of the query.</typeparam>
        /// <param name="key">The filter key associated to the filter.</param>
        /// <param name="queryFilter">The query filter to apply to the the context.</param>
        /// <param name="isEnabled">true if the filter is enabled.</param>
        /// <returns>The filter created and added to the the context.</returns>
        public static BaseQueryFilter Filter <T>(object key, Func <IQueryable <T>, IQueryable <T> > queryFilter, bool isEnabled = true)
        {
            BaseQueryFilter filter;

            if (!GlobalFilters.TryGetValue(key, out filter))
            {
                filter = new QueryFilter <T>(null, queryFilter)
                {
                    IsDefaultEnabled = isEnabled
                };
                GlobalFilters.Add(key, filter);
            }

            return(filter);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Creates and return a filter associated with the specified key added for the context.
        /// </summary>
        /// <typeparam name="T">The type of elements of the query.</typeparam>
        /// <param name="key">The filter key associated to the filter.</param>
        /// <param name="queryFilter">The query filter to apply to the the context.</param>
        /// <param name="isEnabled">true if the filter is enabled.</param>
        /// <returns>The filter created and added to the the context.</returns>
        public static AliasBaseQueryFilter Filter <T>(object key, Func <IQueryable <T>, IQueryable <T> > queryFilter, bool isEnabled = true)
        {
            AliasBaseQueryFilter filter;

            if (!GlobalFilters.TryGetValue(key, out filter))
            {
#if EF6
                filter = new QueryDbSetFilter <T>(null, queryFilter)
                {
                    IsDefaultEnabled = isEnabled
                };
#else
                filter = new QueryFilter <T>(null, queryFilter)
                {
                    IsDefaultEnabled = isEnabled
                };
#endif
                GlobalFilters.Add(key, filter);
            }

            return(filter);
        }