From b241c59c1c8a30d0d3bc16e7f14bd4bb44027012 Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Fri, 19 May 2023 17:47:04 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20=D0=B3?= =?UTF-8?q?=D1=80=D0=B0=D1=84=D0=B8=D0=BA=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ChartLogic.cs | 57 +++++++++++++++++-- .../BusinessLogicContracts/IChartLogic.cs | 4 +- .../ViewModel/TopersViewModel.cs | 9 +++ .../Controllers/HomeController.cs | 20 ++++++- SchoolAgainStudy/TeacherWebClient/Program.cs | 1 + .../Views/Home/TopMaterials.cshtml | 33 +++++++++++ .../Views/Shared/_Layout.cshtml | 6 +- 7 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 SchoolAgainStudy/SchoolAgainStudyContracts/ViewModel/TopersViewModel.cs create mode 100644 SchoolAgainStudy/TeacherWebClient/Views/Home/TopMaterials.cshtml diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ChartLogic.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ChartLogic.cs index 7eb6545..7c417ae 100644 --- a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ChartLogic.cs +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ChartLogic.cs @@ -3,6 +3,8 @@ using SchoolAgainStudyContracts.BusinessLogicContracts; using SchoolAgainStudyContracts.SearchModel; using SchoolAgainStudyContracts.StorageContracts; using SchoolAgainStudyContracts.ViewModel; +using SchoolAgainStudyDataBaseImplements.Models; +using SchoolAgainStudyDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -16,14 +18,19 @@ namespace SchoolAgainStudyBusinessLogic.BusinessLogic private readonly IInterestLogic _interest; private readonly IProductLogic _product; private readonly IDiyLogic _diy; - - public ChartLogic(IInterestLogic interest, IProductLogic product, IDiyLogic diy) + private readonly ILessonLogic _lesson; + private readonly IMaterialLogic _material; + private readonly ITaskLogic _task; + + public ChartLogic(IInterestLogic interest, IProductLogic product, IDiyLogic diy, ILessonLogic lesson, ITaskLogic task, IMaterialLogic mateial) { _interest = interest; _product = product; _diy = diy; - + _lesson = lesson; + _task = task; + _material = mateial; } public (int Products, int Diyes) GetDifferenceInCount(int StudentId) { @@ -73,5 +80,47 @@ namespace SchoolAgainStudyBusinessLogic.BusinessLogic var actList = list.Select(g => new ActivityChartViewModel { dateOf = g.Key.ToString("dd/MM"), count = g.Value }).ToList(); return actList; } - } + + public List GetTopMaterials(int TeacherId) + { + var materials = _material.ReadList(new MaterialSearchModel + { + TeacherId = TeacherId, + }); + var lessons = _lesson.ReadList(new LessonSearchModel + { + TeacherId = TeacherId, + DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc), + DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), + }); + var tasks = _task.ReadList(new TaskSearchModel + { + TeacherId = TeacherId, + DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc), + DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), + }); + Dictionary list = new Dictionary(); + foreach (var material in materials) + { + list.Add(material, 0); + foreach (var lesson in lessons) + { + if (lesson.LessonMaterials.ContainsKey(material.Id)) + list[material] += 1; + } + foreach (var task in tasks) + { + if (task.TaskMaterials.ContainsKey(material.Id)) + list[material] += 1; + } + } + var actList = list.Select(g => new TopersViewModel { Name = g.Key.Title, Count = g.Value }).ToList(); + return actList; + } + + public List GetTopStudents(int TeacherId) + { + throw new NotImplementedException(); + } + } } diff --git a/SchoolAgainStudy/SchoolAgainStudyContracts/BusinessLogicContracts/IChartLogic.cs b/SchoolAgainStudy/SchoolAgainStudyContracts/BusinessLogicContracts/IChartLogic.cs index d56ca98..39dc5c5 100644 --- a/SchoolAgainStudy/SchoolAgainStudyContracts/BusinessLogicContracts/IChartLogic.cs +++ b/SchoolAgainStudy/SchoolAgainStudyContracts/BusinessLogicContracts/IChartLogic.cs @@ -11,5 +11,7 @@ namespace SchoolAgainStudyContracts.BusinessLogicContracts { public (int Products, int Diyes) GetDifferenceInCount(int StudentId); public List GetActivitys(int StudentId); - } + public List GetTopMaterials(int TeacherId); + public List GetTopStudents(int TeacherId); + } } diff --git a/SchoolAgainStudy/SchoolAgainStudyContracts/ViewModel/TopersViewModel.cs b/SchoolAgainStudy/SchoolAgainStudyContracts/ViewModel/TopersViewModel.cs new file mode 100644 index 0000000..a826d98 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyContracts/ViewModel/TopersViewModel.cs @@ -0,0 +1,9 @@ +namespace SchoolAgainStudyContracts.ViewModel +{ + public class TopersViewModel + { + public string Name { get; set; } + public int Count { get; set; } + + } +} diff --git a/SchoolAgainStudy/TeacherWebClient/Controllers/HomeController.cs b/SchoolAgainStudy/TeacherWebClient/Controllers/HomeController.cs index ca0d494..5666b7c 100644 --- a/SchoolAgainStudy/TeacherWebClient/Controllers/HomeController.cs +++ b/SchoolAgainStudy/TeacherWebClient/Controllers/HomeController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; +using Newtonsoft.Json; using SchoolAgainStudyBusinessLogic.MailWorker; using SchoolAgainStudyContracts.BindingModel; using SchoolAgainStudyContracts.BusinessLogicContracts; @@ -21,7 +22,8 @@ namespace TeacherWebClient.Controllers private readonly ITeacherLogic _teacher; private readonly IReportLogic _report; private readonly AbstractMailWorker mailSender; - public HomeController(ILogger logger, IProductLogic product, ILessonLogic lesson, ITaskLogic task, IMaterialLogic material, ITeacherLogic teacher, IReportLogic report, AbstractMailWorker abstractMailWorker) + private readonly IChartLogic _chart; + public HomeController(ILogger logger, IProductLogic product, ILessonLogic lesson, ITaskLogic task, IMaterialLogic material, ITeacherLogic teacher, IReportLogic report, AbstractMailWorker abstractMailWorker, IChartLogic chart) { _logger = logger; _product = product; @@ -30,6 +32,7 @@ namespace TeacherWebClient.Controllers _material = material; _teacher = teacher; _report = report; + _chart = chart; try { @@ -492,5 +495,20 @@ namespace TeacherWebClient.Controllers }); return PartialView("_LessonTaskListPartial", items); } + + [HttpGet] + public IActionResult TopMaterials() + { + if (APIClient.Teacher == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.DataPoints = JsonConvert.SerializeObject(_chart.GetActivitys(APIClient.Teacher.Id), + new JsonSerializerSettings() + { + NullValueHandling = NullValueHandling.Ignore + }); + return View(); + } } } \ No newline at end of file diff --git a/SchoolAgainStudy/TeacherWebClient/Program.cs b/SchoolAgainStudy/TeacherWebClient/Program.cs index b2ecccf..d0965e5 100644 --- a/SchoolAgainStudy/TeacherWebClient/Program.cs +++ b/SchoolAgainStudy/TeacherWebClient/Program.cs @@ -29,6 +29,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddSingleton(); diff --git a/SchoolAgainStudy/TeacherWebClient/Views/Home/TopMaterials.cshtml b/SchoolAgainStudy/TeacherWebClient/Views/Home/TopMaterials.cshtml new file mode 100644 index 0000000..c7e727f --- /dev/null +++ b/SchoolAgainStudy/TeacherWebClient/Views/Home/TopMaterials.cshtml @@ -0,0 +1,33 @@ +@using SchoolAgainStudyContracts.ViewModel; +@model List + + +
+
+ + diff --git a/SchoolAgainStudy/TeacherWebClient/Views/Shared/_Layout.cshtml b/SchoolAgainStudy/TeacherWebClient/Views/Shared/_Layout.cshtml index 3b424d4..f734f9b 100644 --- a/SchoolAgainStudy/TeacherWebClient/Views/Shared/_Layout.cshtml +++ b/SchoolAgainStudy/TeacherWebClient/Views/Shared/_Layout.cshtml @@ -41,7 +41,10 @@ Отчеты + @@ -62,6 +65,7 @@ + @await RenderSectionAsync("Scripts", required: false)