public static void SetFilterGlobalParameterValue(this DbContext context, string filterName, string parameterName, object value)
        {
            //  This is null when called during filter creation in OnModelCreating
            if (context != null)
            {
                context.Database.Initialize(false);
            }

            filterName = ScrubFilterName(filterName);

            if (string.IsNullOrEmpty(parameterName))
            {
                parameterName = GetDefaultParameterNameForFilter(filterName);
            }

            _GlobalParameterValues.AddOrUpdate(filterName,
                                               (f) =>
            {
                var newValues = new DynamicFilterParameters();
                newValues.SetParameter(parameterName, value);
                return(newValues);
            },
                                               (f, currValues) =>
            {
                currValues.SetParameter(parameterName, value);
                return(currValues);
            });
        }
        /// <summary>
        /// Globally disable the filter.  Can be enabled as needed via DbContext.EnableFilter().
        /// </summary>
        /// <param name="modelBuilder"></param>
        /// <param name="filterName"></param>
        public static void DisableFilterGlobally(this DbModelBuilder modelBuilder, string filterName)
        {
            filterName = ScrubFilterName(filterName);

            _GlobalParameterValues.AddOrUpdate(filterName,
                                               (f) =>
            {
                var newValues     = new DynamicFilterParameters();
                newValues.Enabled = false;
                return(newValues);
            },
                                               (f, currValues) =>
            {
                currValues.Enabled = false;
                return(currValues);
            });
        }
        /// <summary>
        /// Set the parameter for a filter within the current DbContext scope.  Once the DbContext is disposed, this
        /// parameter will no longer be in scope and will be removed.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="filterName"></param>
        /// <param name="parameterName"></param>
        /// <param name="value"></param>
        public static void SetFilterScopedParameterValue(this DbContext context, string filterName, string parameterName, object value)
        {
            var filterParams = GetOrCreateScopedFilterParameters(context, filterName);

            if (string.IsNullOrEmpty(parameterName))
            {
                parameterName = GetDefaultParameterNameForFilter(filterName);
            }

            DynamicFilterParameters globalFilterParams = _GlobalParameterValues[filterName];        //  Already validated that this exists.

            if (!globalFilterParams.ParameterValues.ContainsKey(parameterName))
            {
                throw new ApplicationException(string.Format("Parameter {0} not found in Filter {1}", parameterName, filterName));
            }

            filterParams.SetParameter(parameterName, value);
        }
        public static void SetFilterGlobalParameterValue(this DbContext context, string filterName, string parameterName, object value)
        {
            filterName = ScrubFilterName(filterName);

            if (string.IsNullOrEmpty(parameterName))
            {
                parameterName = GetDefaultParameterNameForFilter(filterName);
            }

            _GlobalParameterValues.AddOrUpdate(filterName,
                                               (f) =>
            {
                var newValues = new DynamicFilterParameters();
                newValues.SetParameter(parameterName, value);
                return(newValues);
            },
                                               (f, currValues) =>
            {
                currValues.SetParameter(parameterName, value);
                return(currValues);
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Globally disable the filter.  Can be enabled as needed via DbContext.EnableFilter().
        /// </summary>
        /// <param name="modelBuilder"></param>
        /// <param name="filterName"></param>
        public static void DisableFilterGlobally(this DbModelBuilder modelBuilder, string filterName)
        {
            if (!AreFilterDisabledConditionsAllowed(filterName))
            {
                throw new ApplicationException("Enable/Disable filters conditions have been turned off via PreventDisabledFilterConditions!");
            }

            filterName = ScrubFilterName(filterName);

            _GlobalParameterValues.AddOrUpdate(filterName,
                                               (f) =>
            {
                var newValues     = new DynamicFilterParameters();
                newValues.Enabled = false;
                return(newValues);
            },
                                               (f, currValues) =>
            {
                currValues.Enabled = false;
                return(currValues);
            });
        }