From e7d5e7f5e40cfc72151bced2582d7aa488931b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20=C5=A0inik?= Date: Mon, 27 May 2024 22:23:56 +0200 Subject: [PATCH] [feat] Enable generation of PDF report for average grades of students with 0 to 3 penalties --- LangLang/BusinessLogic/UseCases/PdfService.cs | 17 ++++++++++ .../UseCases/PenaltyPointService.cs | 5 +++ .../BusinessLogic/UseCases/ReportService.cs | 2 +- .../BusinessLogic/UseCases/SenderService.cs | 32 +++++++++++++------ .../DirectorViewModels/ReportsViewModel.cs | 7 ++++ .../WPF/Views/DirectorView/Tabs/Reports.xaml | 2 +- .../Views/DirectorView/Tabs/Reports.xaml.cs | 5 +++ 7 files changed, 59 insertions(+), 11 deletions(-) diff --git a/LangLang/BusinessLogic/UseCases/PdfService.cs b/LangLang/BusinessLogic/UseCases/PdfService.cs index 4e602a8..6f07334 100644 --- a/LangLang/BusinessLogic/UseCases/PdfService.cs +++ b/LangLang/BusinessLogic/UseCases/PdfService.cs @@ -4,6 +4,7 @@ using System.IO; using System; using System.Collections.Generic; +using LangLang.Domain.Models; namespace LangLang.BusinessLogic.UseCases { @@ -50,5 +51,21 @@ public PdfGrid DataToGrid(Dictionary data) return grid; } + public PdfGrid DataToGrid(Dictionary<(Course, int), double> data) + { + PdfGrid grid = new PdfGrid(); + grid.Columns.Add(4); + foreach (var item in data) + { + PdfGridRow row = grid.Rows.Add(); + row.Cells[0].Value = item.Key.Item1.Language; + row.Cells[1].Value = item.Key.Item1.Level.ToString(); + row.Cells[2].Value = item.Key.Item2.ToString(); + row.Cells[3].Value = item.Value.ToString(); + } + + return grid; + } + } } diff --git a/LangLang/BusinessLogic/UseCases/PenaltyPointService.cs b/LangLang/BusinessLogic/UseCases/PenaltyPointService.cs index 8849fac..fd5d625 100644 --- a/LangLang/BusinessLogic/UseCases/PenaltyPointService.cs +++ b/LangLang/BusinessLogic/UseCases/PenaltyPointService.cs @@ -97,6 +97,11 @@ public List GetStudentsByPenaltyCount(Course course, int penaltyCount) { List students = new(); var studentService = new StudentService(); + var courseService = new CourseService(); + + if (penaltyCount == 0) + return courseService.GetStudentsAttended(course); + foreach (var point in GetByCourse(course)) { var student = studentService.Get(point.StudentId); diff --git a/LangLang/BusinessLogic/UseCases/ReportService.cs b/LangLang/BusinessLogic/UseCases/ReportService.cs index dad98fc..4f8fe3d 100644 --- a/LangLang/BusinessLogic/UseCases/ReportService.cs +++ b/LangLang/BusinessLogic/UseCases/ReportService.cs @@ -31,7 +31,7 @@ public Dictionary GetPenaltiesLastYear() foreach (var course in courseService.GetCoursesHeldInLastYear()) { - for (int i = 0; i < Constants.MAX_PENALTY_POINTS; i++) + for (int i = 0; i <= Constants.MAX_PENALTY_POINTS; i++) { var key = (course, i); averageGrades[key] = GetAverageGrade(course, i); diff --git a/LangLang/BusinessLogic/UseCases/SenderService.cs b/LangLang/BusinessLogic/UseCases/SenderService.cs index cab8127..9396d0c 100644 --- a/LangLang/BusinessLogic/UseCases/SenderService.cs +++ b/LangLang/BusinessLogic/UseCases/SenderService.cs @@ -4,6 +4,7 @@ using LangLang.Domain.Models; using LangLang.Domain.RepositoryInterfaces; using LangLang.Utilities; +using System; using System.Collections.Generic; namespace LangLang.BusinessLogic.UseCases @@ -38,6 +39,20 @@ public void SendResults(ExamSlot exam) } } + public void SendGratitudeMail(Course course, List students) + { + foreach (var student in students) + { + string subject = GetGratitudeSubject(); + string body = GetGratitudeMessage(); + + subject = Utils.ReplacePlaceholders(subject, GetSubjectReplacements(course)); + body = Utils.ReplacePlaceholders(body, GetBodyReplacements(student)); + + EmailService.SendEmail(student.Profile.Email, subject, body); + } + } + public void SendAveragePoints(Director director) { var reportService = new ReportService(); @@ -61,18 +76,17 @@ public void SendAveragePenaltyPoints(Director director) var document = PdfService.GeneratePdf>(reportService.GetAveragePenaltyPoints(), headers, reportName, data => pdfService.DataToGrid(data)); EmailService.SendEmail(director.Profile.Email, reportName, "", document); } - public void SendGratitudeMail(Course course, List students) + + internal void SentAverageGradeByPenaltyCount(Director director) { - foreach (var student in students) - { - string subject = GetGratitudeSubject(); - string body = GetGratitudeMessage(); + var reportService = new ReportService(); + var pdfService = new PdfService(); - subject = Utils.ReplacePlaceholders(subject, GetSubjectReplacements(course)); - body = Utils.ReplacePlaceholders(body, GetBodyReplacements(student)); + var reportName = "Average grade by penalty count"; + var headers = new string[] { "Language", "Level", "Num of penalties", "Average grade" }; - EmailService.SendEmail(student.Profile.Email, subject, body); - } + var document = PdfService.GeneratePdf>(reportService.GetAverageGradeByPenaltyCount(), headers, reportName, data => pdfService.DataToGrid(data)); + EmailService.SendEmail(director.Profile.Email, reportName, "", document); } private string[] GetBodyReplacements(ExamResult result, ExamSlot exam) diff --git a/LangLang/WPF/ViewModels/DirectorViewModels/ReportsViewModel.cs b/LangLang/WPF/ViewModels/DirectorViewModels/ReportsViewModel.cs index c951099..d24f305 100644 --- a/LangLang/WPF/ViewModels/DirectorViewModels/ReportsViewModel.cs +++ b/LangLang/WPF/ViewModels/DirectorViewModels/ReportsViewModel.cs @@ -1,5 +1,6 @@ using LangLang.BusinessLogic.UseCases; using LangLang.Domain.Models; +using System; using System.Windows; namespace LangLang.WPF.ViewModels.DirectorViewModels @@ -24,6 +25,12 @@ public void SentAveragePenaltyPoints() senderService.SendAveragePenaltyPoints(_director); ShowSuccess(); } + public void SentAverageGradeByPenaltyCount() + { + var senderService = new SenderService(); + senderService.SentAverageGradeByPenaltyCount(_director); + ShowSuccess(); + } private void ShowSuccess() { diff --git a/LangLang/WPF/Views/DirectorView/Tabs/Reports.xaml b/LangLang/WPF/Views/DirectorView/Tabs/Reports.xaml index 29601f1..9ca4725 100644 --- a/LangLang/WPF/Views/DirectorView/Tabs/Reports.xaml +++ b/LangLang/WPF/Views/DirectorView/Tabs/Reports.xaml @@ -21,7 +21,7 @@