Пример #1
0
        /// <summary>
        /// Loads the kiosk locations.
        /// </summary>
        /// <param name="kioskDevice">The kiosk device.</param>
        /// <param name="location">The location.</param>
        /// <param name="campusId">The campus identifier.</param>
        /// <param name="rockContext">The rock context.</param>
        private static void LoadKioskLocations(KioskDevice kioskDevice, Location location, int?campusId, RockContext rockContext)
        {
            // Get the child locations and the selected location
            var allLocations = new LocationService(rockContext).GetAllDescendentIds(location.Id).ToList();

            allLocations.Add(location.Id);

            var activeSchedules = new Dictionary <int, KioskSchedule>();

            foreach (var groupLocation in new GroupLocationService(rockContext).GetActiveByLocations(allLocations).OrderBy(l => l.Order).AsNoTracking())
            {
                var kioskLocation = new KioskLocation(groupLocation.Location);
                kioskLocation.CampusId = campusId;
                kioskLocation.Order    = groupLocation.Order;

                // Populate each kioskLocation with its schedules (kioskSchedules)
                foreach (var schedule in groupLocation.Schedules.Where(s => s.CheckInStartOffsetMinutes.HasValue))
                {
                    if (activeSchedules.Keys.Contains(schedule.Id))
                    {
                        kioskLocation.KioskSchedules.Add(activeSchedules[schedule.Id]);
                    }
                    else
                    {
                        var kioskSchedule = new KioskSchedule(schedule);
                        kioskSchedule.CheckInTimes = schedule.GetCheckInTimes(RockDateTime.Now);
                        if (kioskSchedule.IsCheckInActive || kioskSchedule.NextActiveDateTime.HasValue)
                        {
                            kioskLocation.KioskSchedules.Add(kioskSchedule);
                            activeSchedules.Add(schedule.Id, kioskSchedule);
                        }
                    }
                }

                // If the group location has any active OR future schedules, add the group's group type to the kiosk's
                // list of group types
                if (kioskLocation.KioskSchedules.Count > 0)
                {
                    KioskGroupType kioskGroupType = kioskDevice.KioskGroupTypes.Where(g => g.GroupType.Id == groupLocation.Group.GroupTypeId).FirstOrDefault();
                    if (kioskGroupType == null)
                    {
                        kioskGroupType = new KioskGroupType(groupLocation.Group.GroupTypeId);
                        kioskDevice.KioskGroupTypes.Add(kioskGroupType);
                    }

                    KioskGroup kioskGroup = kioskGroupType.KioskGroups.Where(g => g.Group.Id == groupLocation.GroupId).FirstOrDefault();
                    if (kioskGroup == null)
                    {
                        kioskGroup = new KioskGroup(groupLocation.Group);
                        kioskGroup.Group.LoadAttributes(rockContext);
                        kioskGroupType.KioskGroups.Add(kioskGroup);
                    }

                    kioskGroup.KioskLocations.Add(kioskLocation);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Loads the kiosk locations.
        /// </summary>
        /// <param name="kioskDevice">The kiosk device.</param>
        /// <param name="location">The location.</param>
        /// <param name="campusId">The campus identifier.</param>
        /// <param name="rockContext">The rock context.</param>
        private static void LoadKioskLocations(KioskDevice kioskDevice, Location location, int?campusId, RockContext rockContext)
        {
            // Get all the child locations also
            var allLocations = new List <int> {
                location.Id
            };

            new LocationService(rockContext)
            .GetAllDescendents(location.Id)
            .Select(l => l.Id)
            .ToList()
            .ForEach(l => allLocations.Add(l));

            foreach (var groupLocation in new GroupLocationService(rockContext).GetActiveByLocations(allLocations))
            {
                var kioskLocation = new KioskLocation(groupLocation.Location);
                kioskLocation.CampusId = campusId;

                // Populate each kioskLocation with its schedules (kioskSchedules)
                foreach (var schedule in groupLocation.Schedules.Where(s => s.CheckInStartOffsetMinutes.HasValue))
                {
                    var nextActiveDateTime = schedule.GetNextCheckInStartTime(RockDateTime.Now);
                    if (nextActiveDateTime.HasValue)
                    {
                        var kioskSchedule = new KioskSchedule(schedule);
                        kioskSchedule.NextActiveDateTime = nextActiveDateTime;
                        kioskLocation.KioskSchedules.Add(kioskSchedule);
                    }
                }

                // If the group location has any active OR future schedules, add the group's group type to the kiosk's
                // list of group types
                if (kioskLocation.KioskSchedules.Count > 0)
                {
                    KioskGroupType kioskGroupType = kioskDevice.KioskGroupTypes.Where(g => g.GroupType.Id == groupLocation.Group.GroupTypeId).FirstOrDefault();
                    if (kioskGroupType == null)
                    {
                        kioskGroupType = new KioskGroupType(groupLocation.Group.GroupTypeId);
                        kioskDevice.KioskGroupTypes.Add(kioskGroupType);
                    }

                    KioskGroup kioskGroup = kioskGroupType.KioskGroups.Where(g => g.Group.Id == groupLocation.GroupId).FirstOrDefault();
                    if (kioskGroup == null)
                    {
                        kioskGroup = new KioskGroup(groupLocation.Group);
                        kioskGroup.Group.LoadAttributes(rockContext);
                        kioskGroupType.KioskGroups.Add(kioskGroup);
                    }

                    kioskGroup.KioskLocations.Add(kioskLocation);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Loads the kiosk locations.
        /// </summary>
        /// <param name="kioskDevice">The kiosk device.</param>
        /// <param name="location">The location.</param>
        /// <param name="rockContext">The rock context.</param>
        private static void LoadKioskLocations( KioskDevice kioskDevice, Location location, RockContext rockContext )
        {
            var groupLocationService = new GroupLocationService( rockContext );
            foreach ( var groupLocation in groupLocationService.GetActiveByLocation( location.Id ) )
            {
                DateTimeOffset nextGroupActiveTime = DateTimeOffset.MaxValue;

                var kioskLocation = new KioskLocation( location );

                // Populate each kioskLocation with it's schedules (kioskSchedules)
                foreach ( var schedule in groupLocation.Schedules.Where( s => s.CheckInStartOffsetMinutes.HasValue ) )
                {
                    var nextScheduleActiveTime = schedule.GetNextCheckInStartTime( DateTimeOffset.Now );
                    if ( nextScheduleActiveTime.HasValue && nextScheduleActiveTime.Value.CompareTo( nextGroupActiveTime.DateTime ) < 0 )
                    {
                        nextGroupActiveTime = nextScheduleActiveTime.Value;
                    }

                    if ( schedule.IsCheckInActive && kioskLocation != null )
                    {
                        kioskLocation.KioskSchedules.Add( new KioskSchedule( schedule ) );
                    }
                }

                // If the group location has any active OR future schedules, add the group's group type to the kiosk's 
                // list of group types
                if ( kioskLocation.KioskSchedules.Count > 0 || nextGroupActiveTime < DateTimeOffset.MaxValue )
                {
                    KioskGroupType kioskGroupType = kioskDevice.KioskGroupTypes.Where( g => g.GroupType.Id == groupLocation.Group.GroupTypeId ).FirstOrDefault();
                    if ( kioskGroupType == null )
                    {
                        kioskGroupType = new KioskGroupType( groupLocation.Group.GroupType );
                        kioskGroupType.GroupType.LoadAttributes();
                        kioskGroupType.NextActiveTime = DateTimeOffset.MaxValue;
                        kioskDevice.KioskGroupTypes.Add( kioskGroupType );
                    }

                    if ( nextGroupActiveTime.CompareTo( kioskGroupType.NextActiveTime ) < 0 )
                    {
                        kioskGroupType.NextActiveTime = nextGroupActiveTime;
                    }

                    // If there are active schedules, add the group to the group type groups
                    if ( kioskLocation.KioskSchedules.Count > 0 )
                    {
                        KioskGroup kioskGroup = kioskGroupType.KioskGroups.Where( g => g.Group.Id == groupLocation.GroupId ).FirstOrDefault();
                        if ( kioskGroup == null )
                        {
                            kioskGroup = new KioskGroup( groupLocation.Group );
                            kioskGroup.Group.LoadAttributes();
                            kioskGroupType.KioskGroups.Add( kioskGroup );
                        }

                        kioskLocation.Location.LoadAttributes();
                        kioskGroup.KioskLocations.Add( kioskLocation );
                    }
                }
            }

            foreach ( var childLocation in location.ChildLocations )
            {
                LoadKioskLocations( kioskDevice, childLocation, rockContext );
            }
        }
Пример #4
0
        /// <summary>
        /// Loads the kiosk locations.
        /// </summary>
        /// <param name="kioskDevice">The kiosk device.</param>
        /// <param name="location">The location.</param>
        /// <param name="campusId">The campus identifier.</param>
        /// <param name="rockContext">The rock context.</param>
        private static void LoadKioskLocations( KioskDevice kioskDevice, Location location, int? campusId, RockContext rockContext )
        {
            // Get all the child locations also
            var allLocations = new List<int> { location.Id };
            new LocationService( rockContext )
                .GetAllDescendents( location.Id )
                .Select( l => l.Id )
                .ToList()
                .ForEach( l => allLocations.Add( l ) );

            foreach ( var groupLocation in new GroupLocationService( rockContext ).GetActiveByLocations( allLocations ) )
            {
                DateTime nextGroupActiveTime = DateTime.MaxValue;

                var kioskLocation = new KioskLocation( groupLocation.Location );
                kioskLocation.CampusId = campusId;

                // Populate each kioskLocation with its schedules (kioskSchedules)
                foreach ( var schedule in groupLocation.Schedules.Where( s => s.CheckInStartOffsetMinutes.HasValue ) )
                {
                    var nextScheduleActiveTime = schedule.GetNextCheckInStartTime( RockDateTime.Now );
                    if ( nextScheduleActiveTime.HasValue &&
                        ( schedule.IsCheckInActive || nextScheduleActiveTime.Value.CompareTo( RockDateTime.Now ) >= 0 ) &&
                        nextScheduleActiveTime.Value.CompareTo( nextGroupActiveTime ) < 0 )
                    {
                        nextGroupActiveTime = nextScheduleActiveTime.Value;
                    }

                    if ( schedule.IsCheckInActive && kioskLocation != null )
                    {
                        kioskLocation.KioskSchedules.Add( new KioskSchedule( schedule ) );
                    }
                }

                // If the group location has any active OR future schedules, add the group's group type to the kiosk's
                // list of group types
                if ( kioskLocation.KioskSchedules.Count > 0 || nextGroupActiveTime < DateTime.MaxValue )
                {
                    KioskGroupType kioskGroupType = kioskDevice.KioskGroupTypes.Where( g => g.GroupType.Id == groupLocation.Group.GroupTypeId ).FirstOrDefault();
                    if ( kioskGroupType == null )
                    {
                        kioskGroupType = new KioskGroupType( groupLocation.Group.GroupTypeId );
                        kioskGroupType.NextActiveTime = DateTime.MaxValue;
                        kioskDevice.KioskGroupTypes.Add( kioskGroupType );
                    }

                    if ( nextGroupActiveTime.CompareTo( kioskGroupType.NextActiveTime ) < 0 )
                    {
                        kioskGroupType.NextActiveTime = nextGroupActiveTime;
                    }

                    // If there are active schedules, add the group to the group type groups
                    if ( kioskLocation.KioskSchedules.Count > 0 )
                    {
                        KioskGroup kioskGroup = kioskGroupType.KioskGroups.Where( g => g.Group.Id == groupLocation.GroupId ).FirstOrDefault();
                        if ( kioskGroup == null )
                        {
                            kioskGroup = new KioskGroup( groupLocation.Group );
                            kioskGroup.Group.LoadAttributes( rockContext );
                            kioskGroupType.KioskGroups.Add( kioskGroup );
                        }

                        //kioskLocation.Location.LoadAttributes( rockContext ); // Locations don't have UI for attributes
                        kioskGroup.KioskLocations.Add( kioskLocation );
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Loads the kiosk locations.
        /// </summary>
        /// <param name="kioskDevice">The kiosk device.</param>
        /// <param name="location">The location.</param>
        /// <param name="campusId">The campus identifier.</param>
        /// <param name="rockContext">The rock context.</param>
        private static void LoadKioskLocations( KioskDevice kioskDevice, Location location, int? campusId, RockContext rockContext )
        {
            // Get the child locations and the selected location
            var allLocations = new LocationService( rockContext ).GetAllDescendentIds( location.Id ).ToList();
            allLocations.Add( location.Id );

            var activeSchedules = new Dictionary<int, KioskSchedule>();

            foreach ( var groupLocation in new GroupLocationService( rockContext ).GetActiveByLocations( allLocations ).OrderBy( l => l.Order ).AsNoTracking() )
            {
                var kioskLocation = new KioskLocation( groupLocation.Location );
                kioskLocation.CampusId = campusId;
                kioskLocation.Order = groupLocation.Order;

                // Populate each kioskLocation with its schedules (kioskSchedules)
                foreach ( var schedule in groupLocation.Schedules.Where( s => s.CheckInStartOffsetMinutes.HasValue ) )
                {
                    if ( activeSchedules.Keys.Contains( schedule.Id ) )
                    {
                        kioskLocation.KioskSchedules.Add( activeSchedules[schedule.Id] );
                    }
                    else
                    {
                        var kioskSchedule = new KioskSchedule( schedule );
                        kioskSchedule.CheckInTimes = schedule.GetCheckInTimes( RockDateTime.Now );
                        if ( kioskSchedule.IsCheckInActive || kioskSchedule.NextActiveDateTime.HasValue )
                        {
                            kioskLocation.KioskSchedules.Add( kioskSchedule );
                            activeSchedules.Add( schedule.Id, kioskSchedule );
                        }
                    }
                }

                // If the group location has any active OR future schedules, add the group's group type to the kiosk's
                // list of group types
                if ( kioskLocation.KioskSchedules.Count > 0 )
                {
                    KioskGroupType kioskGroupType = kioskDevice.KioskGroupTypes.Where( g => g.GroupType.Id == groupLocation.Group.GroupTypeId ).FirstOrDefault();
                    if ( kioskGroupType == null )
                    {
                        kioskGroupType = new KioskGroupType( groupLocation.Group.GroupTypeId );
                        kioskDevice.KioskGroupTypes.Add( kioskGroupType );
                    }

                    KioskGroup kioskGroup = kioskGroupType.KioskGroups.Where( g => g.Group.Id == groupLocation.GroupId ).FirstOrDefault();
                    if ( kioskGroup == null )
                    {
                        kioskGroup = new KioskGroup( groupLocation.Group );
                        kioskGroup.Group.LoadAttributes( rockContext );
                        kioskGroupType.KioskGroups.Add( kioskGroup );
                    }

                    kioskGroup.KioskLocations.Add( kioskLocation );
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Loads the kiosk locations.
        /// </summary>
        /// <param name="kioskDevice">The kiosk device.</param>
        /// <param name="location">The location.</param>
        private static void LoadKioskLocations(KioskDevice kioskDevice, Location location)
        {
            var groupLocationService = new GroupLocationService();

            foreach (var groupLocation in groupLocationService.GetActiveByLocation(location.Id))
            {
                DateTimeOffset nextGroupActiveTime = DateTimeOffset.MaxValue;

                var kioskLocation = new KioskLocation(groupLocation.Location);

                // Populate each kioskLocation with it's schedules (kioskSchedules)
                foreach (var schedule in groupLocation.Schedules.Where(s => s.CheckInStartOffsetMinutes.HasValue))
                {
                    var nextScheduleActiveTime = schedule.GetNextCheckInStartTime(DateTimeOffset.Now);
                    if (nextScheduleActiveTime.HasValue && nextScheduleActiveTime.Value.CompareTo(nextGroupActiveTime.DateTime) < 0)
                    {
                        nextGroupActiveTime = nextScheduleActiveTime.Value;
                    }

                    if (schedule.IsCheckInActive && kioskLocation != null)
                    {
                        kioskLocation.KioskSchedules.Add(new KioskSchedule(schedule));
                    }
                }

                // If the group location has any active OR future schedules, add the group's group type to the kiosk's
                // list of group types
                if (kioskLocation.KioskSchedules.Count > 0 || nextGroupActiveTime < DateTimeOffset.MaxValue)
                {
                    KioskGroupType kioskGroupType = kioskDevice.KioskGroupTypes.Where(g => g.GroupType.Id == groupLocation.Group.GroupTypeId).FirstOrDefault();
                    if (kioskGroupType == null)
                    {
                        kioskGroupType = new KioskGroupType(groupLocation.Group.GroupType);
                        kioskGroupType.GroupType.LoadAttributes();
                        kioskGroupType.NextActiveTime = DateTimeOffset.MaxValue;
                        kioskDevice.KioskGroupTypes.Add(kioskGroupType);
                    }

                    if (nextGroupActiveTime.CompareTo(kioskGroupType.NextActiveTime) < 0)
                    {
                        kioskGroupType.NextActiveTime = nextGroupActiveTime;
                    }

                    // If there are active schedules, add the group to the group type groups
                    if (kioskLocation.KioskSchedules.Count > 0)
                    {
                        KioskGroup kioskGroup = kioskGroupType.KioskGroups.Where(g => g.Group.Id == groupLocation.GroupId).FirstOrDefault();
                        if (kioskGroup == null)
                        {
                            kioskGroup = new KioskGroup(groupLocation.Group);
                            kioskGroup.Group.LoadAttributes();
                            kioskGroupType.KioskGroups.Add(kioskGroup);
                        }

                        kioskLocation.Location.LoadAttributes();
                        kioskGroup.KioskLocations.Add(kioskLocation);
                    }
                }
            }

            foreach (var childLocation in location.ChildLocations)
            {
                LoadKioskLocations(kioskDevice, childLocation);
            }
        }