private List <TemplateContainer> GetCheckInTemplateGroups()
        {
            var checkInGroupTypes = cblCheckInTemplates.SelectedValuesAsInt.Any() ? cblCheckInTemplates.SelectedValuesAsInt.Select(i => _groupTypeService.Get(i)).ToList() : GetCheckInTemplatesGroupTypes();
            var result            = new List <TemplateContainer>();

            foreach (var groupType in checkInGroupTypes)
            {
                var results = new ChildCheckInGroupGenerator().Get(new List <GroupType> {
                    groupType
                });
                result.Add(new TemplateContainer
                {
                    GroupType   = groupType,
                    GroupTypeId = groupType.Id,
                    GroupGuids  = results.Select(g => g.Guid).ToList(),
                    GroupIds    = results.Select(g => g.Id).ToList()
                });
            }
            return(result);
        }
        private void CreateRowsForGroupType(GroupType groupType, List <YearHeadcountComparisonRow> rows)
        {
            var groups = new ChildCheckInGroupGenerator().Get(groupType);

            // Add row to mark group type
            var groupTypeTitleRow = new YearHeadcountComparisonRow(groupType.Name);

            rows.Add(groupTypeTitleRow);

            // Add row for each group in groupType
            var groupTypeRows = new List <YearHeadcountComparisonRow>();

            groupTypeRows.AddRange(groups.Select(CreateStatisticsRow));

            // Calculate group type specific totals
            var totalRow = new YearHeadcountComparisonRow(groupTypeRows.Sum(r => r.TotalMonthly) ?? 0, groupTypeRows.Sum(r => r.AverageMonthlyAttendance) ?? 0.0m, groupTypeRows.Sum(r => r.YearToDateTotal) ?? 0, groupTypeRows.Sum(r => r.YearToDateAverage) ?? 0.0m,
                                                          groupTypeRows.Sum(r => r.ComparisonYearTotalMonthly) ?? 0, groupTypeRows.Sum(r => r.ComparisonYearAverageMonthlyAttendance) ?? 0.0m, groupTypeRows.Sum(r => r.ComparisonYearToDateTotal) ?? 0, groupTypeRows.Sum(r => r.ComparisonYearToDateAverage) ?? 0.0m);

            // Add rows to the list of rows gStatistics will bind
            rows.AddRange(groupTypeRows);
            rows.Add(totalRow);
        }
        private void CreateRowsForGroupType(GroupType groupType, List <QuarterlyHeadcountComparisonRow> rows)
        {
            int comparisonYear = ddlComparisonYear.SelectedValue.AsInteger();
            var groups         = new ChildCheckInGroupGenerator().Get(groupType);

            // Add row to mark group type
            var groupTypeTitleRow = new QuarterlyHeadcountComparisonRow(groupType.Name);

            rows.Add(groupTypeTitleRow);

            // Add row for each group in groupType
            var groupRows = new List <QuarterlyHeadcountComparisonRow>();

            groupRows.AddRange(
                groups.Select(
                    g =>
            {
                return(_statisticCalculator.Calculate(g, _startDateTime, _endDateTime,
                                                      comparisonYear));
            }));

            // Generate total row
            var totalQuarter = new QuarterInformation(groupRows.Sum(qi => qi.Quarter.YearTotal),
                                                      groupRows.Sum(qi => qi.Quarter.Q1Total), groupRows.Sum(qi => qi.Quarter.Q2Total),
                                                      groupRows.Sum(qi => qi.Quarter.Q3Total), groupRows.Sum(qi => qi.Quarter.Q4Total), groupRows.Sum(qi => qi.Quarter.Average));

            var comparisonQuarter = new QuarterInformation(groupRows.Sum(qi => qi.ComparisonQuarter.YearTotal),
                                                           groupRows.Sum(qi => qi.ComparisonQuarter.Q1Total), groupRows.Sum(qi => qi.ComparisonQuarter.Q2Total),
                                                           groupRows.Sum(qi => qi.ComparisonQuarter.Q3Total), groupRows.Sum(qi => qi.ComparisonQuarter.Q4Total), groupRows.Sum(qi => qi.ComparisonQuarter.Average));

            var totalRow = new QuarterlyHeadcountComparisonRow(totalQuarter, comparisonQuarter, comparisonYear);

            // Add rows to the list of rows gStatistics will bind
            rows.AddRange(groupRows);
            rows.Add(totalRow);
        }