Ejemplo n.º 1
0
        /// <summary>
        /// Gets the nearest group.
        /// </summary>
        /// <param name="personId">The person identifier.</param>
        /// <param name="groupTypeId">The group type identifier.</param>
        /// <returns></returns>
        public Group GetNearestGroup(int personId, int groupTypeId)
        {
            var rockContext    = (RockContext)this.Context;
            var personService  = new PersonService(rockContext);
            var personGeopoint = personService.GetGeopoints(personId).FirstOrDefault();

            if (personGeopoint != null)
            {
                var groupLocation = this.Queryable()
                                    .Where(g =>
                                           g.GroupTypeId.Equals(groupTypeId))
                                    .SelectMany(g =>
                                                g.GroupLocations
                                                .Where(gl =>
                                                       gl.Location != null &&
                                                       gl.Location.GeoPoint != null
                                                       )
                                                )
                                    .OrderBy(gl => gl.Location.GeoPoint.Distance(personGeopoint))
                                    .FirstOrDefault();

                if (groupLocation != null)
                {
                    return(groupLocation.Group);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the groups of a particular type that geofence the selected person's mapped location(s)
        /// </summary>
        /// <param name="personId">The person identifier.</param>
        /// <param name="groupTypeGuid">The group type unique identifier.</param>
        /// <returns></returns>
        public IQueryable <Group> GetGeofencingGroups(int personId, Guid groupTypeGuid)
        {
            var rockContext     = (RockContext)this.Context;
            var personService   = new PersonService(rockContext);
            var personGeopoints = personService.GetGeopoints(personId);

            return(GetGeofencingGroups(personGeopoints, groupTypeGuid));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the nearest group.
        /// </summary>
        /// <param name="personId">The person identifier.</param>
        /// <param name="groupTypeId">The group type identifier.</param>
        /// <returns></returns>
        public Group GetNearestGroup( int personId, int groupTypeId )
        {
            var rockContext = (RockContext)this.Context;
            var personService = new PersonService( rockContext );
            var personGeopoint = personService.GetGeopoints( personId ).FirstOrDefault();
            if ( personGeopoint != null )
            {
                var groupLocation = this.Queryable()
                    .Where( g =>
                        g.GroupTypeId.Equals( groupTypeId ) )
                    .SelectMany( g =>
                        g.GroupLocations
                            .Where( gl =>
                                gl.Location != null &&
                                gl.Location.GeoPoint != null
                            )
                    )
                    .OrderBy( gl => gl.Location.GeoPoint.Distance( personGeopoint ) )
                    .FirstOrDefault();

                if ( groupLocation != null )
                {
                    return groupLocation.Group;
                }
            }

            return null;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets the groups of a particular type that geofence the selected person's mapped location(s)
 /// </summary>
 /// <param name="personId">The person identifier.</param>
 /// <param name="groupTypeGuid">The group type unique identifier.</param>
 /// <returns></returns>
 public IQueryable<Group> GetGeofencingGroups( int personId, Guid groupTypeGuid )
 {
     var rockContext = (RockContext)this.Context;
     var personService = new PersonService( rockContext );
     var personGeopoints = personService.GetGeopoints( personId );
     return GetGeofencingGroups( personGeopoints, groupTypeGuid );
 }