From a7ba3c4a23494e6f4d79ce9d57e3eed7d02faa3f Mon Sep 17 00:00:00 2001 From: Sergei <42182128+SergeiKisa@users.noreply.github.com> Date: Fri, 11 Feb 2022 15:02:07 +0200 Subject: [PATCH 1/3] added functional export student group result to html --- .../ExportFileServices/ExportServiceHtml.cs | 15 ++- .../Html/StudentGroupResultsExportHTML.cs | 101 ++++++++++++++++++ 2 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 CharlieBackend.Business/Services/FileServices/ExportFileServices/Html/StudentGroupResultsExportHTML.cs diff --git a/CharlieBackend.Business/Services/FileServices/ExportFileServices/ExportServiceHtml.cs b/CharlieBackend.Business/Services/FileServices/ExportFileServices/ExportServiceHtml.cs index 16bfb8f02..71a348620 100644 --- a/CharlieBackend.Business/Services/FileServices/ExportFileServices/ExportServiceHtml.cs +++ b/CharlieBackend.Business/Services/FileServices/ExportFileServices/ExportServiceHtml.cs @@ -55,11 +55,18 @@ public async Task> GetStudentClassbook(StudentsClassbookResultDt "student classbook can't be returned in html format"); } - public Task> GetStudentGroupResults(StudentGroupsResultsDto data) + public async Task> GetStudentGroupResults(StudentGroupsResultsDto data) { - return Task.FromResult(Result.GetError( - ErrorCode.ValidationError, - "student classbook can't be returned in html format")); + using var studentGroupResults = new StudentGroupResultsExportHTML("StudentGroupResults"); + + studentGroupResults.FillFileAsync(data); + + return Result.GetSuccess(new FileDto() + { + ByteArray = await studentGroupResults.GetByteArrayAsync(), + ContentType = studentGroupResults.GetContentType(), + Filename = studentGroupResults.GetFileName() + }); } public Task> GetStudentResults(StudentsResultsDto data) diff --git a/CharlieBackend.Business/Services/FileServices/ExportFileServices/Html/StudentGroupResultsExportHTML.cs b/CharlieBackend.Business/Services/FileServices/ExportFileServices/Html/StudentGroupResultsExportHTML.cs new file mode 100644 index 000000000..168774d9d --- /dev/null +++ b/CharlieBackend.Business/Services/FileServices/ExportFileServices/Html/StudentGroupResultsExportHTML.cs @@ -0,0 +1,101 @@ +using CharlieBackend.Core.DTO.Dashboard; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CharlieBackend.Business.Services.FileServices.ExportFileServices.Html +{ + public class StudentGroupResultsExportHTML : BaseFileExportHTML + { + private string _fileName; + private const int _CourseColumnNumber = 0; + private const int _StudentGroupColumnNumber = 1; + private const int _AverageMarkColumnNumber = 2; + + public StudentGroupResultsExportHTML(string fileName) + { + _fileName = fileName; + } + public void FillFileAsync(StudentGroupsResultsDto data) + { + if (data == null) + { + return; + } + if (data.AverageStudentGroupsMarks != null && data.AverageStudentGroupsMarks.Any()) + { + FillAverageMarks(data.AverageStudentGroupsMarks); + } + if (data.AverageStudentGroupsVisits != null && data.AverageStudentGroupsVisits.Any()) + { + FillAverageVisits(data.AverageStudentGroupsVisits); + } + } + + public void FillAverageMarks(IEnumerable AverageStudentGroupsMarks) + { + if (AverageStudentGroupsMarks != null && AverageStudentGroupsMarks.Any()) + { + var orderedList = AverageStudentGroupsMarks.OrderBy(x => x.StudentGroup); + string[] headers = new string[] { "Course", "Student Group", "Average mark" }; + string[][] rows = new string[orderedList.Count()][]; + + for (int i = 0; i < rows.Length; i++) + { + var group = orderedList.ElementAt(i); + rows[i] = new string[headers.Length]; + rows[i][_CourseColumnNumber] = AverageStudentGroupsMarks.First().Course; + rows[i][_StudentGroupColumnNumber] = group.StudentGroup; + rows[i][_AverageMarkColumnNumber] = Math.Round((decimal)group.AverageMark,2).ToString(); + } + + StringBuilder table = HtmlGenerator.GenerateTable(headers, rows); + StringBuilder html = HtmlGenerator.GenerateHtml(_fileName, table); + byte[] byteLine = ConvertLineToArray(html.ToString()); + _memoryStream.Write(byteLine); + } + } + public void FillAverageVisits(IEnumerable AverageStudentGroupsVisits) + { + if (AverageStudentGroupsVisits != null && AverageStudentGroupsVisits.Any()) + { + var orderedList = AverageStudentGroupsVisits.OrderBy(x => x.StudentGroup); + string[] headers = new string[] { "Course", "Student Group", "Average visits" }; + string[][] rows = new string[orderedList.Count()][]; + + for (int i = 0; i < rows.Length; i++) + { + var group = orderedList.ElementAt(i); + rows[i] = new string[headers.Length]; + rows[i][_CourseColumnNumber] = AverageStudentGroupsVisits.First().Course; + rows[i][_StudentGroupColumnNumber] = group.StudentGroup; + rows[i][_AverageMarkColumnNumber] = ((double)group.AverageVisitPercentage / 100).ToString(); + } + + StringBuilder table = HtmlGenerator.GenerateTable(headers, rows); + StringBuilder html = HtmlGenerator.GenerateHtml(_fileName, table); + byte[] byteLine = ConvertLineToArray(html.ToString()); + _memoryStream.Write(byteLine); + + } + } + + private byte[] ConvertLineToArray(string line) + { + byte[] array = new byte[line.Length]; + + for (int i = 0; i < line.Length; i++) + { + array[i] = (byte)line[i]; + } + + return array; + } + public override string GetFileName() + { + return "StudentGroupResult_" + DateTime.Now.ToString("yyyy-MM-dd") + ".html"; + } + } +} From 178ee6a37eeda2bbb75c571923c43086f4601357 Mon Sep 17 00:00:00 2001 From: Sergei <42182128+SergeiKisa@users.noreply.github.com> Date: Wed, 16 Feb 2022 14:08:56 +0200 Subject: [PATCH 2/3] corrected remarks --- .../ExportFileServices/ExportServiceHtml.cs | 2 +- .../Html/StudentGroupResultsExportHTML.cs | 19 ++++++++----------- .../StudentsGroupsResultsDto.cs | 7 +++++++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CharlieBackend.Business/Services/FileServices/ExportFileServices/ExportServiceHtml.cs b/CharlieBackend.Business/Services/FileServices/ExportFileServices/ExportServiceHtml.cs index 71a348620..34c99c2c7 100644 --- a/CharlieBackend.Business/Services/FileServices/ExportFileServices/ExportServiceHtml.cs +++ b/CharlieBackend.Business/Services/FileServices/ExportFileServices/ExportServiceHtml.cs @@ -57,7 +57,7 @@ public async Task> GetStudentClassbook(StudentsClassbookResultDt public async Task> GetStudentGroupResults(StudentGroupsResultsDto data) { - using var studentGroupResults = new StudentGroupResultsExportHTML("StudentGroupResults"); + using var studentGroupResults = new StudentGroupResultsExportHTML("Student Group Results"); studentGroupResults.FillFileAsync(data); diff --git a/CharlieBackend.Business/Services/FileServices/ExportFileServices/Html/StudentGroupResultsExportHTML.cs b/CharlieBackend.Business/Services/FileServices/ExportFileServices/Html/StudentGroupResultsExportHTML.cs index 168774d9d..5faeeffba 100644 --- a/CharlieBackend.Business/Services/FileServices/ExportFileServices/Html/StudentGroupResultsExportHTML.cs +++ b/CharlieBackend.Business/Services/FileServices/ExportFileServices/Html/StudentGroupResultsExportHTML.cs @@ -24,19 +24,14 @@ public void FillFileAsync(StudentGroupsResultsDto data) { return; } - if (data.AverageStudentGroupsMarks != null && data.AverageStudentGroupsMarks.Any()) - { - FillAverageMarks(data.AverageStudentGroupsMarks); - } - if (data.AverageStudentGroupsVisits != null && data.AverageStudentGroupsVisits.Any()) - { - FillAverageVisits(data.AverageStudentGroupsVisits); - } + FillAverageMarks(data.AverageStudentGroupsMarks); + + FillAverageVisits(data.AverageStudentGroupsVisits); } public void FillAverageMarks(IEnumerable AverageStudentGroupsMarks) { - if (AverageStudentGroupsMarks != null && AverageStudentGroupsMarks.Any()) + if (AverageStudentGroupsMarks.Any()) { var orderedList = AverageStudentGroupsMarks.OrderBy(x => x.StudentGroup); string[] headers = new string[] { "Course", "Student Group", "Average mark" }; @@ -48,7 +43,7 @@ public void FillAverageMarks(IEnumerable AverageStud rows[i] = new string[headers.Length]; rows[i][_CourseColumnNumber] = AverageStudentGroupsMarks.First().Course; rows[i][_StudentGroupColumnNumber] = group.StudentGroup; - rows[i][_AverageMarkColumnNumber] = Math.Round((decimal)group.AverageMark,2).ToString(); + rows[i][_AverageMarkColumnNumber] = Math.Round((decimal)group.AverageMark, 2).ToString(); } StringBuilder table = HtmlGenerator.GenerateTable(headers, rows); @@ -57,9 +52,10 @@ public void FillAverageMarks(IEnumerable AverageStud _memoryStream.Write(byteLine); } } + public void FillAverageVisits(IEnumerable AverageStudentGroupsVisits) { - if (AverageStudentGroupsVisits != null && AverageStudentGroupsVisits.Any()) + if (AverageStudentGroupsVisits.Any()) { var orderedList = AverageStudentGroupsVisits.OrderBy(x => x.StudentGroup); string[] headers = new string[] { "Course", "Student Group", "Average visits" }; @@ -93,6 +89,7 @@ private byte[] ConvertLineToArray(string line) return array; } + public override string GetFileName() { return "StudentGroupResult_" + DateTime.Now.ToString("yyyy-MM-dd") + ".html"; diff --git a/CharlieBackend.Core/DTO/Dashboard/StudentGroupResults/StudentsGroupsResultsDto.cs b/CharlieBackend.Core/DTO/Dashboard/StudentGroupResults/StudentsGroupsResultsDto.cs index cbe9ee189..8e4a107bd 100644 --- a/CharlieBackend.Core/DTO/Dashboard/StudentGroupResults/StudentsGroupsResultsDto.cs +++ b/CharlieBackend.Core/DTO/Dashboard/StudentGroupResults/StudentsGroupsResultsDto.cs @@ -7,5 +7,12 @@ public class StudentGroupsResultsDto public IEnumerable AverageStudentGroupsVisits { get; set; } public IEnumerable AverageStudentGroupsMarks { get; set; } + + public StudentGroupsResultsDto() + { + AverageStudentGroupsVisits = new List(); + AverageStudentGroupsMarks = new List(); + } + } } From 7a0c770077bc254ba8b6c00e48e61f14c40d1504 Mon Sep 17 00:00:00 2001 From: Sergei <42182128+SergeiKisa@users.noreply.github.com> Date: Mon, 4 Apr 2022 15:30:03 +0300 Subject: [PATCH 3/3] Fix bag with Event Time --- .../ScheduleServiceFolder/Helpers/SchedulesUpdater.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CharlieBackend.Business/Services/ScheduleServiceFolder/Helpers/SchedulesUpdater.cs b/CharlieBackend.Business/Services/ScheduleServiceFolder/Helpers/SchedulesUpdater.cs index 7ee944f82..0060d835e 100644 --- a/CharlieBackend.Business/Services/ScheduleServiceFolder/Helpers/SchedulesUpdater.cs +++ b/CharlieBackend.Business/Services/ScheduleServiceFolder/Helpers/SchedulesUpdater.cs @@ -11,9 +11,9 @@ public static ScheduledEvent UpdateFields(ScheduledEvent item, UpdateScheduledEv item.MentorId = request.MentorId ?? item.MentorId; item.StudentGroupId = request.StudentGroupId ?? item.StudentGroupId; item.ThemeId = request.ThemeId ?? item.ThemeId; - item.EventStart = request.EventStart.HasValue ? new DateTime(item.EventStart.Year, item.EventStart.Month, item.EventStart.Day, + item.EventStart = request.EventStart.HasValue ? new DateTime(request.EventStart.Value.Year, request.EventStart.Value.Month, request.EventStart.Value.Day, request.EventStart.Value.Hour, request.EventStart.Value.Minute, request.EventStart.Value.Second) : item.EventStart; - item.EventFinish = request.EventEnd.HasValue ? new DateTime(item.EventFinish.Year, item.EventFinish.Month, item.EventFinish.Day, + item.EventFinish = request.EventEnd.HasValue ? new DateTime(request.EventEnd.Value.Year, request.EventEnd.Value.Month, request.EventEnd.Value.Day, request.EventEnd.Value.Hour, request.EventEnd.Value.Minute, request.EventEnd.Value.Second) : item.EventFinish; return item;