/// <summary> /// Gets the regional group attendances. /// </summary> /// <param name="parentGroupGuid">The parent group unique identifier.</param> /// <param name="startDate">The start date.</param> /// <param name="endDate">The end date.</param> /// <returns>The regional group attendances.</returns> private IList <RegionalGroupAttendance> GetRegionalGroupAttendances(Guid parentGroupGuid, DateTime startDate, DateTime endDate) { // Get the parent group. Group parentGroup = _groupService.GetNoTracking(parentGroupGuid); if (parentGroup == null) { _errors.Add("Unable to retrieve the selected parent group."); return(null); } // Get the regional groups under the parent group. var regionalGroups = _groupService.Queryable() .AsNoTracking() .Where(g => g.ParentGroupId == parentGroup.Id && g.IsActive == true) .ToList(); if (!regionalGroups.Any()) { _warnings.Add($"No regional groups found under the '{parentGroup.Name}' parent group."); return(null); } var regionalGroupAttendances = new List <RegionalGroupAttendance>(); foreach (var regionalGroup in regionalGroups) { var leaders = _groupMemberService.GetLeadersWithActiveEmails(regionalGroup.Id) .AsNoTracking() .ToList(); if (!leaders.Any()) { _warnings.Add($"No leaders with active email addresses found for the '{regionalGroup.Name}' regional group."); continue; } var regionalGroupAttendance = new RegionalGroupAttendance { Group = regionalGroup, Leaders = leaders.Select(l => l.Person).ToList(), GroupAttendances = GetChildrenGroupAttendances(regionalGroup, startDate, endDate) }; // Only add this regional group if it has child group attendances to report. if (regionalGroupAttendance.GroupAttendances?.Any() == true) { regionalGroupAttendances.Add(regionalGroupAttendance); } } return(regionalGroupAttendances); }