/// <summary> /// Finds all approved prayer requests for the given selected categories and orders them by least prayed-for. /// Also updates the prayer count for the first item in the list. /// </summary> /// <param name="categoriesList"></param> private void SetAndDisplayPrayerRequests(RockCheckBoxList categoriesList) { RockContext rockContext = new RockContext(); PrayerRequestService service = new PrayerRequestService(rockContext); var prayerRequestQuery = service.GetByCategoryIds(categoriesList.SelectedValuesAsInt); var campusId = cpCampus.SelectedValueAsInt(); if (campusId.HasValue) { prayerRequestQuery = prayerRequestQuery.Where(a => a.CampusId == campusId); } var limitToPublic = GetAttributeValue(PUBLIC_ONLY).AsBoolean(); if (limitToPublic) { prayerRequestQuery = prayerRequestQuery.Where(a => a.IsPublic.HasValue && a.IsPublic.Value); } var prayerRequests = prayerRequestQuery.OrderByDescending(p => p.IsUrgent).ThenBy(p => p.PrayerCount).ToList(); List <int> list = prayerRequests.Select(p => p.Id).ToList <int>(); PrayerRequestIds = list; if (list.Count > 0) { UpdateSessionCountLabel(1, list.Count); hfPrayerIndex.Value = "0"; PrayerRequest request = prayerRequests.First(); ShowPrayerRequest(request, rockContext); } }
/// <summary> /// Gets the prayer requests for the new session. /// </summary> /// <returns>An enumerable of <see cref="PrayerRequest"/> objects.</returns> protected virtual IEnumerable <PrayerRequest> GetPrayerRequests(RockContext rockContext) { var prayerRequestService = new PrayerRequestService(rockContext); var category = CategoryCache.Get(PrayerCategory); if (category == null) { return(null); } var query = prayerRequestService.GetByCategoryIds(new List <int> { category.Id }); if (PublicOnly) { query = query.Where(a => a.IsPublic.HasValue && a.IsPublic.Value); } if (MyCampus) { var campusId = RequestContext.CurrentPerson?.PrimaryCampusId; if (campusId.HasValue) { query = query.Where(a => a.CampusId.HasValue && a.CampusId == campusId); } } query = query.OrderByDescending(a => a.IsUrgent) .ThenBy(a => a.PrayerCount); return(query); }
/// <summary> /// Finds all approved prayer requests for the given selected categories and orders them by least prayed-for. /// Also updates the prayer count for the first item in the list. /// </summary> /// <param name="categoriesList"></param> private void SetAndDisplayPrayerRequests(RockCheckBoxList categoriesList) { PrayerRequestService service = new PrayerRequestService(); var prayerRequests = service.GetByCategoryIds(categoriesList.SelectedValuesAsInt).OrderByDescending(p => p.IsUrgent).ThenBy(p => p.PrayerCount); List <int> list = prayerRequests.Select(p => p.Id).ToList <int>(); Session[_sessionKey] = list; if (list.Count > 0) { UpdateSessionCountLabel(1, list.Count); hfPrayerIndex.Value = "0"; PrayerRequest request = prayerRequests.First(); ShowPrayerRequest(request, service); } }
/// <summary> /// Gets the prayer requests for the new session. /// </summary> /// <returns>An enumerable of <see cref="PrayerRequest"/> objects.</returns> protected virtual IEnumerable <PrayerRequest> GetPrayerRequests(RockContext rockContext) { var prayerRequestService = new PrayerRequestService(rockContext); var category = CategoryCache.Get(PrayerCategory); if (category == null && !GroupGuid.HasValue) { return(null); } var query = prayerRequestService.GetByCategoryIds(new List <int> { category.Id }); if (PublicOnly) { query = query.Where(a => a.IsPublic.HasValue && a.IsPublic.Value); } if (MyCampus) { var campusId = RequestContext.CurrentPerson?.PrimaryCampusId; if (campusId.HasValue) { query = query.Where(a => a.CampusId.HasValue && a.CampusId == campusId); } } // Filter by group if it has been specified. if (GroupGuid.HasValue) { query = query.Where(a => a.Group != null && a.Group.Guid == GroupGuid.Value); } // If we are not filtering by group, then exclude any group requests // unless the block setting including them is enabled. if (!GroupGuid.HasValue && !IncludeGroupRequests) { query = query.Where(a => !a.GroupId.HasValue); } query = query.OrderByDescending(a => a.IsUrgent) .ThenBy(a => a.PrayerCount); return(query); }