Exemple #1
0
        /// <summary>
        /// Get the people's Ids inside a DataView filter.
        /// </summary>
        /// <param name="dataViewId">The data view identifier.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns>Returns a directory of people IDs that result from applying the DataView filter</returns>
        public Dictionary <int, int> DataViewPeopleDirectory(int dataViewId, RockContext rockContext)
        {
            var dataViewService = new DataViewService(rockContext);
            var dataView        = dataViewService.GetNoTracking(dataViewId);

            // Verify that there is not a child filter that uses this view (would result in stack-overflow error)
            if (dataViewService.IsViewInFilter(dataView.Id, dataView.DataViewFilter))
            {
                throw new Exception("Data View Filter issue(s): One of the filters contains a circular reference to the Data View itself.");
            }

            // Evaluate the Data View that defines the candidate population.
            List <string> errorMessages;

            var personService = new PersonService(rockContext);

            var personQuery = personService.Queryable().AsNoTracking();

            var paramExpression = personService.ParameterExpression;

            var whereExpression = dataView.GetExpression(personService, paramExpression, out errorMessages);

            if (errorMessages.Any())
            {
                throw new Exception("Data View Filter issue(s): " + errorMessages.AsDelimited("; "));
            }

            return(personQuery.Where(paramExpression, whereExpression, null).Select(p => p.Id).ToDictionary(p => p, p => p));
        }
Exemple #2
0
        /// <summary>
        /// Returns the field's current value(s)
        /// </summary>
        /// <param name="parentControl">The parent control.</param>
        /// <param name="value">Information about the value</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param>
        /// <returns></returns>
        public override string FormatValue(Control parentControl, string value, Dictionary <string, ConfigurationValue> configurationValues, bool condensed)
        {
            string formattedValue = string.Empty;

            Guid?guid = value.AsGuidOrNull();

            if (guid.HasValue)
            {
                using (var rockContext = new RockContext())
                {
                    var service  = new DataViewService(rockContext);
                    var dataview = service.GetNoTracking(guid.Value);

                    if (dataview != null)
                    {
                        formattedValue = dataview.Name;
                    }
                }
            }

            return(base.FormatValue(parentControl, formattedValue, null, condensed));
        }