示例#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="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 );
                }
            }
        }