/// <summary> /// Gets the data items to be included in the grid. /// </summary> /// <param name="groupId"></param> private List <RSVPListOccurrence> GetGroupRSVP(int groupId) { DateTime? fromDateTime = drpDates.LowerValue; DateTime? toDateTime = drpDates.UpperValue; List <int> locationIds = new List <int>(); List <int> scheduleIds = new List <int>(); // Location Filter if (ddlLocation.Visible) { int?locationId = ddlLocation.SelectedValue.AsIntegerOrNull(); if (locationId.HasValue) { locationIds.Add(locationId.Value); } } //// Schedule Filter //if ( ddlSchedule.Visible ) //{ // int? scheduleId = ddlSchedule.SelectedValue.AsIntegerOrNull(); // if ( scheduleId.HasValue ) // { // scheduleIds.Add( scheduleId.Value ); // } //} var rockContext = new RockContext(); var groupService = new GroupService(rockContext); var group = groupService.Get(groupId); //int invitedCount = group.ActiveMembers().Count(); // Get all the occurrences for this group for the selected dates, location and schedule var occurrences = new AttendanceOccurrenceService(rockContext) .GetGroupOccurrences(group, fromDateTime, toDateTime, locationIds, scheduleIds) .Select(o => new RSVPListOccurrence(o)) .ToList(); // Sort the occurrences List <RSVPListOccurrence> sortedOccurrences = null; if (gRSVPItems.SortProperty != null) { sortedOccurrences = occurrences.AsQueryable().Sort(gRSVPItems.SortProperty).ToList(); } else { sortedOccurrences = occurrences.OrderByDescending(a => a.OccurrenceDate).ThenByDescending(a => a.StartTime).ToList(); } return(sortedOccurrences); }
/// <summary> /// Binds the group members grid. /// </summary> protected void BindGrid() { if (_group != null) { lHeading.Text = _group.Name; DateTime? fromDateTime = drpDates.LowerValue; DateTime? toDateTime = drpDates.UpperValue; List <int> locationIds = new List <int>(); List <int> scheduleIds = new List <int>(); // Location Filter if (ddlLocation.Visible) { string locValue = ddlLocation.SelectedValue; if (locValue.StartsWith("P")) { int?parentLocationId = locValue.Substring(1).AsIntegerOrNull(); if (parentLocationId.HasValue) { locationIds = new LocationService(_rockContext) .GetAllDescendents(parentLocationId.Value) .Select(l => l.Id) .ToList(); } } else { int?locationId = locValue.AsIntegerOrNull(); if (locationId.HasValue) { locationIds.Add(locationId.Value); } } } // Schedule Filter if (ddlSchedule.Visible && ddlSchedule.SelectedValue != "0") { scheduleIds.Add(ddlSchedule.SelectedValueAsInt() ?? 0); } // Get all the occurrences for this group for the selected dates, location and schedule var occurrences = new AttendanceOccurrenceService(_rockContext) .GetGroupOccurrences(_group, fromDateTime, toDateTime, locationIds, scheduleIds) .Select(o => new AttendanceListOccurrence(o)) .ToList(); var locationService = new LocationService(_rockContext); // Check to see if filtering by campus, and if so, only select those occurrences who's // location is associated with that campus (or not associated with any campus) int?campusId = bddlCampus.SelectedValueAsInt(); if (campusId.HasValue) { // If campus filter is selected, load all the descendent locations for each campus into a dictionary var locCampus = new Dictionary <int, int>(); foreach (var campus in CampusCache.All().Where(c => c.LocationId.HasValue)) { locCampus.AddOrIgnore(campus.LocationId.Value, campus.Id); foreach (var locId in locationService.GetAllDescendentIds(campus.LocationId.Value)) { locCampus.AddOrIgnore(locId, campus.Id); } } // Using that dictionary, set the campus id for each occurrence foreach (var occ in occurrences) { if (occ.LocationId.HasValue && locCampus.ContainsKey(occ.LocationId.Value)) { occ.CampusId = locCampus[occ.LocationId.Value]; } } // Remove the occurrences that are associated with another campus occurrences = occurrences .Where(o => !o.CampusId.HasValue || o.CampusId.Value == campusId.Value) .ToList(); } // Update the Parent Location path foreach (int parentLocationId in occurrences .Where(o => o.ParentLocationId.HasValue) .Select(o => o.ParentLocationId.Value) .Distinct()) { string parentLocationPath = locationService.GetPath(parentLocationId); foreach (var occ in occurrences .Where(o => o.ParentLocationId.HasValue && o.ParentLocationId.Value == parentLocationId)) { occ.ParentLocationPath = parentLocationPath; } } // Sort the occurrences SortProperty sortProperty = gOccurrences.SortProperty; List <AttendanceListOccurrence> sortedOccurrences = null; if (sortProperty != null) { if (sortProperty.Property == "LocationPath,LocationName") { if (sortProperty.Direction == SortDirection.Ascending) { sortedOccurrences = occurrences.OrderBy(o => o.ParentLocationPath).ThenBy(o => o.LocationName).ToList(); } else { sortedOccurrences = occurrences.OrderByDescending(o => o.ParentLocationPath).ThenByDescending(o => o.LocationName).ToList(); } } else { sortedOccurrences = occurrences.AsQueryable().Sort(sortProperty).ToList(); } } else { sortedOccurrences = occurrences.OrderByDescending(a => a.OccurrenceDate).ThenByDescending(a => a.StartTime).ToList(); } gOccurrences.DataSource = sortedOccurrences; gOccurrences.DataBind(); } }