GetByDevice() public method

Gets the locations associated to a device and optionally any child locaitons
public GetByDevice ( int deviceId, bool includeChildLocations = true ) : IEnumerable
deviceId int The device identifier.
includeChildLocations bool if set to true [include child locations].
return IEnumerable
Ejemplo n.º 1
0
        /// <summary>
        /// Gets the device group types.
        /// </summary>
        /// <param name="deviceId">The device identifier.</param>
        /// <returns></returns>
        private List<GroupType> GetDeviceGroupTypes( int deviceId )
        {
            var groupTypes = new Dictionary<int, GroupType>();

            var locationService = new LocationService( new RockContext() );

            // Get all locations (and their children) associated with device
            var locationIds = locationService
                .GetByDevice(deviceId, true)
                .Select( l => l.Id)
                .ToList();

            // Requery using EF
            foreach ( var groupType in locationService.Queryable()
                .Where( l => locationIds.Contains( l.Id ) )
                .SelectMany( l => l.GroupLocations )
                .Select( gl => gl.Group.GroupType )
                .ToList() )
            {
                if ( !groupTypes.ContainsKey( groupType.Id ) )
                {
                    groupTypes.Add( groupType.Id, groupType );
                }
            }

            return groupTypes.Select( g => g.Value ).ToList();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the device group types.
        /// </summary>
        /// <param name="deviceId">The device identifier.</param>
        /// <returns></returns>
        private List<GroupType> GetDeviceGroupTypes( int deviceId, RockContext rockContext )
        {
            var groupTypes = new Dictionary<int, GroupType>();

            var locationService = new LocationService( rockContext );

            // Get all locations (and their children) associated with device
            var locationIds = locationService
                .GetByDevice( deviceId, true )
                .Select( l => l.Id )
                .ToList();

            // Requery using EF
            foreach ( var groupType in locationService
                .Queryable().AsNoTracking()
                .Where( l => locationIds.Contains( l.Id ) )
                .SelectMany( l => l.GroupLocations )
                .Where( gl => gl.Group.GroupType.TakesAttendance )
                .Select( gl => gl.Group.GroupType )
                .ToList() )
            {
                groupTypes.AddOrIgnore( groupType.Id, groupType );
            }

            return groupTypes
                .Select( g => g.Value )
                .OrderBy( g => g.Order )
                .ToList();
        }