public GetByDevice ( int deviceId, bool includeChildLocations = true ) : IEnumerable |
||
deviceId | int | The device identifier. |
includeChildLocations | bool | if set to |
return | IEnumerable |
/// <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(); }
/// <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(); }