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 @@ +