public void CreateReportCard(string outFilename, MarkingPeriod period) { var currentSubjects = _student.Grades.GroupBy(g => g.Subject) .Where(subject => subject.Any(subGrade => subGrade.IsCurrentForPeriod(period.Key))) .OrderBy(subject => Maintenance.GetSubjectIndex(subject.Key)); var gradeReportFields = currentSubjects.Select((subject, i) => { var thisYearsGrades = subject.Where(subGrade => subGrade.ShouldShowOnReportCard(period)) .Select(subGrade => subGrade.GetGradeReportFields(period.Key, i + 1)); return(thisYearsGrades.SelectMany(x => x)); }).SelectMany(x => x); var outputProperties = gradeReportFields.Concat(GetPDFFields(this)) .Concat(GetReportLevelFields(period.Key)) .Concat(GetSelfDevFields(period.Key)); if (outFilename == null) { var tempDir = Path.GetTempPath(); Directory.CreateDirectory(tempDir); string tempFileName = Path.Combine(tempDir, GetDefaultReportCardFilename(period.Key) + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf"); PDFWriter.WritePDF(tempFileName, outputProperties.ToDictionary(p => p.Key, p => p.Value)); Process.Start(tempFileName); } else { PDFWriter.WritePDF(outFilename, outputProperties.ToDictionary(p => p.Key, p => p.Value)); } }