public SlidesResponse GetContentChannel(string id) { var rockContext = new RockContext(); var contentChannelService = new ContentChannelService(rockContext); var response = new SlidesResponse(); var contentChannel = contentChannelService.Get(id.AsInteger()); if (contentChannel != null) { response.Contents = GetContentChannelItems(new List <int>(), contentChannel, rockContext); } response.GenerateHash(); return(response); }
public SlidesResponse GetSlides(string id) { var rockContext = new RockContext(); var deviceService = new DeviceService(rockContext); var scheduleService = new ScheduleService(rockContext); var contentChannelService = new ContentChannelService(rockContext); var response = new SlidesResponse(); Device device = deviceService.Get(id.AsInteger()); if (device != null) { var campuses = device.Locations.Select(l => l.CampusId).Where(c => c.HasValue && c.Value != 0).Select(c => c.Value).ToList(); device.LoadAttributes(rockContext); var definedValueGuids = device.GetAttributeValue("com_shepherdchurch_ContentSchedules").SplitDelimitedValues().AsGuidList(); List <DefinedValueCache> definedValues = new List <DefinedValueCache>(); // // Build a list of the cached defined values so we can then sort by Order. // foreach (var definedValueGuid in definedValueGuids) { var definedValue = DefinedValueCache.Get(definedValueGuid); if (definedValue != null) { definedValues.Add(definedValue); } } // // Check each defined value they have selected on this device and look for the // first one that is active. // foreach (var definedValue in definedValues.OrderBy(d => d.Order)) { var contentChannel = contentChannelService.Get(definedValue.GetAttributeValue("com_shepherdchurch_ContentChannel").AsGuid()); if (contentChannel != null) { var schedules = definedValue.GetAttributeValues("com_shepherdchurch_Schedules").AsGuidList(); bool scheduleActive = false; // // Check if either no schedules (match by default) or any single schedule // is currently active. // if (!schedules.Any()) { scheduleActive = true; } else { foreach (var guid in schedules) { var schedule = scheduleService.Get(guid); if (schedule.WasScheduleActive(RockDateTime.Now)) { scheduleActive = true; break; } } } // // If the schedule is active, then this is the content channel we are going // to work with. Build our list of image URLs and audio URLs. // if (scheduleActive) { response.Contents = GetContentChannelItems(campuses, contentChannel, rockContext); break; } } } response.GenerateHash(); } return(response); }