GetByDevice() 공개 메소드

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].
리턴 IEnumerable
예제 #1
0
파일: Admin.ascx.cs 프로젝트: Ganon11/Rock
        /// <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();
        }
예제 #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();
        }