From b3a2699d7d6ff773558df359915d3edf3e986706 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Fri, 19 May 2023 18:30:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D1=80=D0=B0=D1=84=D0=B8=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ChartLogic.cs | 39 ++++++++++++++++++- .../Controllers/HomeController.cs | 16 +++++++- .../Views/Home/TopStudents.cshtml | 33 ++++++++++++++++ .../Views/Shared/_Layout.cshtml | 3 ++ 4 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 SchoolAgainStudy/TeacherWebClient/Views/Home/TopStudents.cshtml diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ChartLogic.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ChartLogic.cs index 7c417ae..bdee914 100644 --- a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ChartLogic.cs +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ChartLogic.cs @@ -21,8 +21,9 @@ namespace SchoolAgainStudyBusinessLogic.BusinessLogic private readonly ILessonLogic _lesson; private readonly IMaterialLogic _material; private readonly ITaskLogic _task; + private readonly IStudentLogic _student; - public ChartLogic(IInterestLogic interest, IProductLogic product, IDiyLogic diy, ILessonLogic lesson, ITaskLogic task, IMaterialLogic mateial) + public ChartLogic(IInterestLogic interest, IProductLogic product, IDiyLogic diy, ILessonLogic lesson, ITaskLogic task, IMaterialLogic mateial, IStudentLogic student) { _interest = interest; @@ -31,6 +32,7 @@ namespace SchoolAgainStudyBusinessLogic.BusinessLogic _lesson = lesson; _task = task; _material = mateial; + _student = student; } public (int Products, int Diyes) GetDifferenceInCount(int StudentId) { @@ -120,7 +122,40 @@ namespace SchoolAgainStudyBusinessLogic.BusinessLogic public List GetTopStudents(int TeacherId) { - throw new NotImplementedException(); + var lessons = _lesson.ReadList(new LessonSearchModel + { + TeacherId = TeacherId + }); + var tasks = _task.ReadList(new TaskSearchModel + { + TeacherId = TeacherId, + }); + var diys = _diy.ReadList(null); + Dictionary list = new Dictionary(); + foreach(var lesson in lessons) + { + var product = _product.ReadElement(new ProductSearchModel + { + Id = lesson.ProductId + }); + if (list.ContainsKey(product.StudentId)) + list[product.StudentId] += 1; + else list.Add(product.StudentId, 1); + } + foreach (var task in tasks) + { + foreach(var diy in diys) + { + if(diy.TaskId == task.Id) + { + if (list.ContainsKey(diy.StudentId)) + list[diy.StudentId] += 1; + else list.Add(diy.StudentId, 1); + } + } + } + var actList = list.Select(g => new TopersViewModel { Name = _student.ReadElement(new StudentSearchModel { Id = g.Key }).Name, Count = g.Value }).ToList(); + return actList; } } } diff --git a/SchoolAgainStudy/TeacherWebClient/Controllers/HomeController.cs b/SchoolAgainStudy/TeacherWebClient/Controllers/HomeController.cs index 5666b7c..77aa178 100644 --- a/SchoolAgainStudy/TeacherWebClient/Controllers/HomeController.cs +++ b/SchoolAgainStudy/TeacherWebClient/Controllers/HomeController.cs @@ -503,7 +503,21 @@ namespace TeacherWebClient.Controllers { return Redirect("~/Home/Enter"); } - ViewBag.DataPoints = JsonConvert.SerializeObject(_chart.GetActivitys(APIClient.Teacher.Id), + ViewBag.DataPoints = JsonConvert.SerializeObject(_chart.GetTopMaterials(APIClient.Teacher.Id), + new JsonSerializerSettings() + { + NullValueHandling = NullValueHandling.Ignore + }); + return View(); + } + [HttpGet] + public IActionResult TopStudents() + { + if (APIClient.Teacher == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.DataPoints = JsonConvert.SerializeObject(_chart.GetTopStudents(APIClient.Teacher.Id), new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore diff --git a/SchoolAgainStudy/TeacherWebClient/Views/Home/TopStudents.cshtml b/SchoolAgainStudy/TeacherWebClient/Views/Home/TopStudents.cshtml new file mode 100644 index 0000000..a695894 --- /dev/null +++ b/SchoolAgainStudy/TeacherWebClient/Views/Home/TopStudents.cshtml @@ -0,0 +1,33 @@ +@using SchoolAgainStudyContracts.ViewModel; +@model List + + +
+
+ + \ No newline at end of file diff --git a/SchoolAgainStudy/TeacherWebClient/Views/Shared/_Layout.cshtml b/SchoolAgainStudy/TeacherWebClient/Views/Shared/_Layout.cshtml index f734f9b..151a279 100644 --- a/SchoolAgainStudy/TeacherWebClient/Views/Shared/_Layout.cshtml +++ b/SchoolAgainStudy/TeacherWebClient/Views/Shared/_Layout.cshtml @@ -46,6 +46,9 @@ +