Beispiel #1
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(Type entityType, object serviceInstance, Expression parameterExpression, string selection)
        {
            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length >= 2)
            {
                GroupMemberService groupMemberService = new GroupMemberService();
                int groupTypeId = selectionValues[0].AsInteger() ?? 0;

                var groupMemberServiceQry = groupMemberService.Queryable().Where(xx => xx.Group.GroupTypeId == groupTypeId);

                var groupRoleIds = selectionValues[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(n => int.Parse(n)).ToList();
                if (groupRoleIds.Count() > 0)
                {
                    groupMemberServiceQry = groupMemberServiceQry.Where(xx => groupRoleIds.Contains(xx.GroupRoleId));
                }

                var qry = new Rock.Data.Service <Rock.Model.Person>().Queryable()
                          .Where(p => groupMemberServiceQry.Any(xx => xx.PersonId == p.Id));

                Expression extractedFilterExpression = FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p");

                return(extractedFilterExpression);
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(Type entityType, object serviceInstance, Expression parameterExpression, string selection)
        {
            var qry = new Rock.Data.Service <Rock.Model.Person>().Queryable()
                      .Where(p => p.PhotoId.HasValue == (selection == "1"));

            return(FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p"));
        }
Beispiel #3
0
        /// <summary>
        /// Creates the control(s) neccessary for prompting user for a new value
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id"></param>
        /// <returns>
        /// The control
        /// </returns>
        public override Control EditControl(Dictionary <string, ConfigurationValue> configurationValues, string id)
        {
            ListControl editControl = null;

            if (configurationValues != null)
            {
                if (configurationValues.ContainsKey("fieldtype") && configurationValues["fieldtype"].Value == "rb")
                {
                    editControl = new RockRadioButtonList {
                        ID = id
                    };
                    ((RadioButtonList)editControl).RepeatDirection = RepeatDirection.Horizontal;
                }
                else
                {
                    editControl = new RockDropDownList {
                        ID = id
                    };
                }

                if (configurationValues.ContainsKey("values"))
                {
                    string listSource = configurationValues["values"].Value;

                    if (listSource.ToUpper().Contains("SELECT") && listSource.ToUpper().Contains("FROM"))
                    {
                        var       tableValues = new List <string>();
                        DataTable dataTable   = new Rock.Data.Service().GetDataTable(listSource, CommandType.Text, null);
                        if (dataTable != null && dataTable.Columns.Contains("Value") && dataTable.Columns.Contains("Text"))
                        {
                            foreach (DataRow row in dataTable.Rows)
                            {
                                editControl.Items.Add(new ListItem(row["text"].ToString(), row["value"].ToString()));
                            }
                        }
                    }

                    else
                    {
                        foreach (string keyvalue in listSource.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            var keyValueArray = keyvalue.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                            if (keyValueArray.Length > 0)
                            {
                                ListItem li = new ListItem();
                                li.Value = keyValueArray[0];
                                li.Text  = keyValueArray.Length > 1 ? keyValueArray[1] : keyValueArray[0];
                                editControl.Items.Add(li);
                            }
                        }
                    }
                }
            }

            return(editControl);
        }
Beispiel #4
0
        /// <summary>
        /// Builds the expression.
        /// </summary>
        /// <param name="idQuery">The id query.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <returns></returns>
        private Expression BuildExpression(IQueryable <int> idQuery, Expression parameterExpression)
        {
            Guid adultGuid = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid();
            Guid childGuid = Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD.AsGuid();

            var qry = new Rock.Data.Service <Rock.Model.Person>().Queryable()
                      .Where(p => p.Members.Where(a => a.GroupRole.Guid == adultGuid)
                             .Any(a => a.Group.Members
                                  .Any(c => c.GroupRole.Guid == childGuid && idQuery.Contains(c.PersonId))));

            return(FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p"));
        }
Beispiel #5
0
        /// <summary>
        /// Reloads the attribute values.
        /// </summary>
        public virtual void ReloadAttributeValues()
        {
            var service = new Rock.Data.Service <T>();
            var model   = service.Get(this.Id);

            if (model != null)
            {
                model.LoadAttributes();

                this.AttributeValues = model.AttributeValues;
                this.Attributes      = model.Attributes;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Saves the attribute values.
        /// </summary>
        /// <param name="personId">The person id.</param>
        public virtual void SaveAttributeValues(int?personId)
        {
            var service = new Rock.Data.Service <T>();
            var model   = service.Get(this.Id);

            if (model != null)
            {
                model.LoadAttributes();
                foreach (var attribute in model.Attributes)
                {
                    if (this.AttributeValues.ContainsKey(attribute.Key))
                    {
                        Rock.Attribute.Helper.SaveAttributeValues(model, attribute.Value, this.AttributeValues[attribute.Key], personId);
                    }
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression(Type entityType, object serviceInstance, Expression parameterExpression, string selection)
        {
            string[] selectionValues = selection.Split('|');
            if (selectionValues.Length >= 2)
            {
                Location location = new LocationService().Get(selectionValues[0].AsInteger() ?? 0);

                if (location == null)
                {
                    return(null);
                }

                var    selectedLocationGeoPoint = location.GeoPoint;
                double miles = 0;
                double.TryParse(selectionValues[1], out miles);

                double meters = miles * 1609.344;

                GroupMemberService groupMemberService = new GroupMemberService();

                // limit to Family's Home Addresses that have are a real location (not a PO Box)
                var groupMemberServiceQry = groupMemberService.Queryable()
                                            .Where(xx => xx.Group.GroupType.Guid == new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY))
                                            .Where(xx => xx.Group.GroupLocations
                                                   .Where(l => l.GroupLocationTypeValue.Guid == new Guid(Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME))
                                                   .Where(l => l.IsMappedLocation).Any());

                // limit to distance LessThan specified distance (dbGeography uses meters for distance units)
                groupMemberServiceQry = groupMemberServiceQry
                                        .Where(xx => xx.Group.GroupLocations.Any(l => l.Location.GeoPoint.Distance(selectedLocationGeoPoint) <= meters));

                var qry = new Rock.Data.Service <Rock.Model.Person>().Queryable()
                          .Where(p => groupMemberServiceQry.Any(xx => xx.PersonId == p.Id));

                Expression extractedFilterExpression = FilterExpressionExtractor.Extract <Rock.Model.Person>(qry, parameterExpression, "p");

                return(extractedFilterExpression);
            }

            return(null);
        }
Beispiel #8
0
        /// <summary>
        /// Creates the control(s) neccessary for prompting user for a new value
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id"></param>
        /// <returns>
        /// The control
        /// </returns>
        public override Control EditControl( Dictionary<string, ConfigurationValue> configurationValues, string id )
        {
            ListControl editControl = null;

            if ( configurationValues != null )
            {
                if ( configurationValues.ContainsKey( "fieldtype" ) && configurationValues["fieldtype"].Value == "rb" )
                {
                    editControl = new RockRadioButtonList { ID = id }; 
                    ( (RadioButtonList)editControl ).RepeatDirection = RepeatDirection.Horizontal;
                }
                else
                {
                    editControl = new RockDropDownList { ID = id }; 
                }

                if ( configurationValues.ContainsKey( "values" ) )
                {
                    string listSource = configurationValues["values"].Value;

                    if ( listSource.ToUpper().Contains( "SELECT" ) && listSource.ToUpper().Contains( "FROM" ) )
                    {
                        var tableValues = new List<string>();
                        DataTable dataTable = new Rock.Data.Service().GetDataTable( listSource, CommandType.Text, null );
                        if ( dataTable != null && dataTable.Columns.Contains( "Value" ) && dataTable.Columns.Contains( "Text" ) )
                        {
                            foreach ( DataRow row in dataTable.Rows )
                            {
                                editControl.Items.Add( new ListItem( row["text"].ToString(), row["value"].ToString() ) );
                            }
                        }
                    }

                    else
                    {
                        foreach ( string keyvalue in listSource.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) )
                        {
                            var keyValueArray = keyvalue.Split( new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries );
                            if ( keyValueArray.Length > 0 )
                            {
                                ListItem li = new ListItem();
                                li.Value = keyValueArray[0];
                                li.Text = keyValueArray.Length > 1 ? keyValueArray[1] : keyValueArray[0];
                                editControl.Items.Add( li );
                            }
                        }
                    }
                }
            }

            return editControl;
        }
Beispiel #9
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression( Type entityType, object serviceInstance, Expression parameterExpression, string selection )
        {
            string[] selectionValues = selection.Split( '|' );
            if ( selectionValues.Length >= 2 )
            {
                GroupMemberService groupMemberService = new GroupMemberService();
                int groupId = selectionValues[0].AsInteger() ?? 0;

                var groupMemberServiceQry = groupMemberService.Queryable().Where( xx => xx.GroupId == groupId );

                var groupRoleIds = selectionValues[1].Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ).Select( n => int.Parse( n ) ).ToList();
                if ( groupRoleIds.Count() > 0 )
                {
                    groupMemberServiceQry = groupMemberServiceQry.Where( xx => groupRoleIds.Contains(xx.GroupRoleId) );
                }

                var qry = new Rock.Data.Service<Rock.Model.Person>().Queryable()
                    .Where( p => groupMemberServiceQry.Any( xx => xx.PersonId == p.Id ) );

                Expression extractedFilterExpression = FilterExpressionExtractor.Extract<Rock.Model.Person>( qry, parameterExpression, "p" );

                return extractedFilterExpression;
            }

            return null;
        }
Beispiel #10
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression( Type entityType, object serviceInstance, Expression parameterExpression, string selection )
        {
            string[] selectionValues = selection.Split( '|' );
            if ( selectionValues.Length >= 2 )
            {
                Location location = new LocationService().Get( selectionValues[0].AsInteger() ?? 0 );

                if ( location == null )
                {
                    return null;
                }

                var selectedLocationGeoPoint = location.GeoPoint;
                double miles = 0;
                double.TryParse( selectionValues[1], out miles );

                double meters = miles * 1609.344;

                GroupMemberService groupMemberService = new GroupMemberService();

                // limit to Family's Home Addresses that have are a real location (not a PO Box)
                var groupMemberServiceQry = groupMemberService.Queryable()
                    .Where( xx => xx.Group.GroupType.Guid == new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY ) )
                    .Where( xx => xx.Group.GroupLocations
                        .Where( l => l.GroupLocationTypeValue.Guid == new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME ) )
                        .Where( l => l.IsMappedLocation ).Any() );

                // limit to distance LessThan specified distance (dbGeography uses meters for distance units)
                groupMemberServiceQry = groupMemberServiceQry
                    .Where( xx => xx.Group.GroupLocations.Any( l => l.Location.GeoPoint.Distance( selectedLocationGeoPoint ) <= meters ) );

                var qry = new Rock.Data.Service<Rock.Model.Person>().Queryable()
                    .Where( p => groupMemberServiceQry.Any( xx => xx.PersonId == p.Id ) );

                Expression extractedFilterExpression = FilterExpressionExtractor.Extract<Rock.Model.Person>( qry, parameterExpression, "p" );

                return extractedFilterExpression;
            }

            return null;
        }
Beispiel #11
0
        /// <summary>
        /// Gets the expression.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="serviceInstance">The service instance.</param>
        /// <param name="parameterExpression">The parameter expression.</param>
        /// <param name="selection">The selection.</param>
        /// <returns></returns>
        public override Expression GetExpression( Type entityType, object serviceInstance, Expression parameterExpression, string selection )
        {
            var qry = new Rock.Data.Service<Rock.Model.Person>().Queryable()
                .Where( p => p.PhotoId.HasValue == ( selection == "1" ) );

            return FilterExpressionExtractor.Extract<Rock.Model.Person>( qry, parameterExpression, "p" );
        }