diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ChartLogic.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ChartLogic.cs new file mode 100644 index 0000000..7eb6545 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ChartLogic.cs @@ -0,0 +1,77 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage; +using SchoolAgainStudyContracts.BusinessLogicContracts; +using SchoolAgainStudyContracts.SearchModel; +using SchoolAgainStudyContracts.StorageContracts; +using SchoolAgainStudyContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.BusinessLogic +{ + public class ChartLogic : IChartLogic + { + private readonly IInterestLogic _interest; + private readonly IProductLogic _product; + private readonly IDiyLogic _diy; + + public ChartLogic(IInterestLogic interest, IProductLogic product, IDiyLogic diy) + { + + _interest = interest; + _product = product; + _diy = diy; + + } + public (int Products, int Diyes) GetDifferenceInCount(int StudentId) + { + var products = _product.ReadList(new ProductSearchModel + { + StudentId = StudentId, + DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc), + DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), + }); + var diyes = _diy.ReadList(new DiySearchModel + { + StudentId = StudentId, + DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc), + DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), + }); + return (products.Count, diyes.Count); + } + public List GetActivitys(int StudentId) + { + var products = _product.ReadList(new ProductSearchModel + { + StudentId = StudentId, + DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc), + DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), + }); + var diyes = _diy.ReadList(new DiySearchModel + { + StudentId = StudentId, + DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc), + DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), + }); + Dictionary list = new Dictionary(); + for(DateTime date = DateTime.Now.AddMonths(-1); date<= DateTime.Now; date=date.AddDays(1)) + { + list.Add(date, 0); + foreach(var product in products) + { + if (product.DateCreate.Date == date.Date) + list[date] += 1; + } + foreach (var diy in diyes) + { + if (diy.DateCreate.Date == date.Date) + list[date] += 1; + } + } + var actList = list.Select(g => new ActivityChartViewModel { dateOf = g.Key.ToString("dd/MM"), count = g.Value }).ToList(); + return actList; + } + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/SchoolAgainStudyBusinessLogic.csproj b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/SchoolAgainStudyBusinessLogic.csproj index 881cfb1..c40c622 100644 --- a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/SchoolAgainStudyBusinessLogic.csproj +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/SchoolAgainStudyBusinessLogic.csproj @@ -17,7 +17,6 @@ - diff --git a/SchoolAgainStudy/SchoolAgainStudyContracts/BusinessLogicContracts/IChartLogic.cs b/SchoolAgainStudy/SchoolAgainStudyContracts/BusinessLogicContracts/IChartLogic.cs new file mode 100644 index 0000000..d56ca98 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyContracts/BusinessLogicContracts/IChartLogic.cs @@ -0,0 +1,15 @@ +using SchoolAgainStudyContracts.ViewModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyContracts.BusinessLogicContracts +{ + public interface IChartLogic + { + public (int Products, int Diyes) GetDifferenceInCount(int StudentId); + public List GetActivitys(int StudentId); + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyContracts/SchoolAgainStudyContracts.csproj b/SchoolAgainStudy/SchoolAgainStudyContracts/SchoolAgainStudyContracts.csproj index 28b2e82..320cc92 100644 --- a/SchoolAgainStudy/SchoolAgainStudyContracts/SchoolAgainStudyContracts.csproj +++ b/SchoolAgainStudy/SchoolAgainStudyContracts/SchoolAgainStudyContracts.csproj @@ -11,10 +11,8 @@ - - diff --git a/SchoolAgainStudy/SchoolAgainStudyContracts/ViewModel/ActivityChartViewModel.cs b/SchoolAgainStudy/SchoolAgainStudyContracts/ViewModel/ActivityChartViewModel.cs new file mode 100644 index 0000000..10bebfe --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyContracts/ViewModel/ActivityChartViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyContracts.ViewModel +{ + public class ActivityChartViewModel + { + public string dateOf { get; set; } = string.Empty; + public int count { get; set; } + + } +} diff --git a/SchoolAgainStudy/StudentWebClient/Controllers/HomeController.cs b/SchoolAgainStudy/StudentWebClient/Controllers/HomeController.cs index 08edbe4..b983b0b 100644 --- a/SchoolAgainStudy/StudentWebClient/Controllers/HomeController.cs +++ b/SchoolAgainStudy/StudentWebClient/Controllers/HomeController.cs @@ -1,16 +1,17 @@ -using DocumentFormat.OpenXml.Wordprocessing; +using DocumentFormat.OpenXml.Drawing; +using DocumentFormat.OpenXml.Wordprocessing; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; +using Newtonsoft.Json; using SchoolAgainStudyBusinessLogic.MailWorker; using SchoolAgainStudyContracts.BindingModel; using SchoolAgainStudyContracts.BusinessLogicContracts; using SchoolAgainStudyContracts.SearchModel; -using SchoolAgainStudyContracts.ViewModel; -using SchoolAgainStudyDataBaseImplements.Models; using SchoolAgainStudyDataModels.Models; using StudentWebClient.Models; +using System.Collections; using System.Diagnostics; -using System.IO; +using System.Linq.Expressions; namespace StudentWebClient.Controllers { @@ -23,9 +24,11 @@ namespace StudentWebClient.Controllers private readonly IInterestLogic _interest; private readonly IStudentLogic _student; private readonly IReportLogic _report; + private readonly IChartLogic _chart; private readonly AbstractMailWorker mailSender; public HomeController(ILogger logger, IDiyLogic diy, - IProductLogic product , ITaskLogic task , IInterestLogic interest, IStudentLogic student, IReportLogic report, AbstractMailWorker abstractMailWorker) + IProductLogic product , ITaskLogic task , IInterestLogic interest, + IStudentLogic student, IReportLogic report, AbstractMailWorker abstractMailWorker, IChartLogic chartLogic) { _logger = logger; _diy = diy; @@ -34,6 +37,7 @@ namespace StudentWebClient.Controllers _interest = interest; _student = student; _report = report; + _chart = chartLogic; try { @@ -251,7 +255,7 @@ namespace StudentWebClient.Controllers { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate) || task <=0 || interests.Length==0) + if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate) || task <=0 ) { throw new Exception("Введите название и описане"); } @@ -305,10 +309,7 @@ namespace StudentWebClient.Controllers { throw new Exception("Нет задания"); } - if (interests.Length == 0) - { - throw new Exception("Нет интересов"); - } + Dictionary diyInterests = new Dictionary(); foreach (int id in interests) @@ -364,7 +365,7 @@ namespace StudentWebClient.Controllers { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate)|| interests.Length == 0) + if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate)) { throw new Exception("Введите название и описане"); } @@ -411,10 +412,7 @@ namespace StudentWebClient.Controllers { throw new Exception("Нет даты"); } - if (interests.Length == 0) - { - throw new Exception("Нет интересов"); - } + Dictionary productInterests = new Dictionary(); foreach (int id in interests) @@ -493,10 +491,33 @@ namespace StudentWebClient.Controllers mailSender.MailSendAsync(new MailSendInfoBindingModel { MailAddress = APIClient.Student.Email, - Subject = "Заказ номер", + Subject = $"Отчет от {dateFrom} по {dateTo}", Path = path }); - return PartialView("_LessonListPartial", items); + return PartialView("_InterestListPartial", items); } + [HttpGet] + public IActionResult WorksCharts() + { + if (APIClient.Student == null) + { + return Redirect("~/Home/Enter"); + } + return View(_chart.GetDifferenceInCount(APIClient.Student.Id)); + } + [HttpGet] + public IActionResult ActivityCharts() + { + if (APIClient.Student == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.DataPoints = JsonConvert.SerializeObject(_chart.GetActivitys(APIClient.Student.Id), + new JsonSerializerSettings() { + NullValueHandling = NullValueHandling.Ignore}); + return View(); + } + + } } \ No newline at end of file diff --git a/SchoolAgainStudy/StudentWebClient/Program.cs b/SchoolAgainStudy/StudentWebClient/Program.cs index 756597f..59e8afb 100644 --- a/SchoolAgainStudy/StudentWebClient/Program.cs +++ b/SchoolAgainStudy/StudentWebClient/Program.cs @@ -32,6 +32,8 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); + builder.Services.AddSingleton(); diff --git a/SchoolAgainStudy/StudentWebClient/Views/Home/ActivityCharts.cshtml b/SchoolAgainStudy/StudentWebClient/Views/Home/ActivityCharts.cshtml new file mode 100644 index 0000000..b03f6e7 --- /dev/null +++ b/SchoolAgainStudy/StudentWebClient/Views/Home/ActivityCharts.cshtml @@ -0,0 +1,33 @@ +@using SchoolAgainStudyContracts.ViewModel; +@model List + + +
+
+ + \ No newline at end of file diff --git a/SchoolAgainStudy/StudentWebClient/Views/Home/WorksCharts.cshtml b/SchoolAgainStudy/StudentWebClient/Views/Home/WorksCharts.cshtml new file mode 100644 index 0000000..c093e49 --- /dev/null +++ b/SchoolAgainStudy/StudentWebClient/Views/Home/WorksCharts.cshtml @@ -0,0 +1,30 @@ +@model System.ValueTuple + + +
+
+ + \ No newline at end of file diff --git a/SchoolAgainStudy/StudentWebClient/Views/Home/_InterestListPartial.cshtml b/SchoolAgainStudy/StudentWebClient/Views/Home/_InterestListPartial.cshtml index 2d21d9d..ab966b7 100644 --- a/SchoolAgainStudy/StudentWebClient/Views/Home/_InterestListPartial.cshtml +++ b/SchoolAgainStudy/StudentWebClient/Views/Home/_InterestListPartial.cshtml @@ -9,12 +9,20 @@ - Название + Интерес - Интересы + Изделие + + + Дата создания + + + Поделка + + + Дата создания - @@ -24,6 +32,18 @@ @Html.DisplayFor(modelItem => item.InterestTitle) + + @Html.DisplayFor(modelItem => item.ProductTitle) + + + @Html.DisplayFor(modelItem => item.DateCreateProduct) + + + @Html.DisplayFor(modelItem => item.DiyTitle) + + + @Html.DisplayFor(modelItem => item.DateCreateDiy) + } diff --git a/SchoolAgainStudy/StudentWebClient/Views/Shared/_Layout.cshtml b/SchoolAgainStudy/StudentWebClient/Views/Shared/_Layout.cshtml index 66e64a2..9573365 100644 --- a/SchoolAgainStudy/StudentWebClient/Views/Shared/_Layout.cshtml +++ b/SchoolAgainStudy/StudentWebClient/Views/Shared/_Layout.cshtml @@ -10,6 +10,7 @@ + @await RenderSectionAsync("Scripts", required: false) @@ -47,6 +48,12 @@ + +