/// <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); } }