From 3226311dd2c654830b2169f8e5765d79a4b1ef15 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Thu, 30 May 2024 00:31:58 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D0=BF=D0=BE=D1=87=D1=82=D1=83=20=D0=BF?= =?UTF-8?q?=D0=B4=D1=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 6 ++-- .../Controllers/HomeController.cs | 35 ++++++++++++++----- .../Views/Home/ReportDisciplines.cshtml | 7 ++++ .../BusinessLogicsContracts/IReportLogic.cs | 2 +- .../UniversityDatabase.cs | 2 +- .../Controllers/DisciplineController .cs | 34 +++++++++++++++++- 6 files changed, 71 insertions(+), 15 deletions(-) diff --git a/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs index ff35281..26be5c5 100644 --- a/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs @@ -252,13 +252,13 @@ public class ReportLogic : IReportLogic }); } - public void SendDisciplinesToEmail(ReportDateRangeBindingModel option, string email) + public void SendDisciplinesToEmail(ReportDateRangeBindingModel option) { - _saveToPdfWorker.CreateDoc(new PdfInfoWorker + _saveToPdfStorekeeper.CreateDoc(new PdfInfoStorekeeper { FileName = option.FileName, Title = "Отчёт по дисциплинам", - PlanOfStudyAndStudent = GetPlanOfStudyAndStudents() + Disciplines = GetDisciplines(option) }); } diff --git a/University/UniversityClientApp/Controllers/HomeController.cs b/University/UniversityClientApp/Controllers/HomeController.cs index 69e8eed..54f2fcf 100644 --- a/University/UniversityClientApp/Controllers/HomeController.cs +++ b/University/UniversityClientApp/Controllers/HomeController.cs @@ -217,15 +217,32 @@ namespace UniversityClientApp.Controllers } } - /*[HttpGet] - public IActionResult ReportDisciplines() - { - if (APIStorekeeper.Client == null) - { - return Redirect("~/Home/Enter"); - } - return View(); - }*/ + [HttpPost] + public void ReportDisciplines(string type, DateOnly dateFrom, DateOnly dateTo) + { + if (APIStorekeeper.Client == null) + { + Redirect("~/Home/Enter"); + throw new Exception(" "); + } + if (type == "pdf") + { + APIStorekeeper.PostRequest("api/discipline/createreporttopdffile", new ReportDateRangeBindingModel + { + FileName = "C:\\\\ .pdf", + DateFrom = dateFrom, + DateTo = dateTo + }); + APIStorekeeper.PostRequest("api/discipline/sendpdftomail", new MailSendInfoBindingModel + { + MailAddress = APIStorekeeper.Client.Email, + Subject = "", + Text = " " + }); + } + Response.Redirect("Index"); + return; + } [HttpGet] public IActionResult ReportDisciplines(DateOnly dateFrom, DateOnly dateTo) diff --git a/University/UniversityClientApp/Views/Home/ReportDisciplines.cshtml b/University/UniversityClientApp/Views/Home/ReportDisciplines.cshtml index 032cd1b..406cf1e 100644 --- a/University/UniversityClientApp/Views/Home/ReportDisciplines.cshtml +++ b/University/UniversityClientApp/Views/Home/ReportDisciplines.cshtml @@ -16,6 +16,13 @@
+ + + + +
+ +
@if (Model != null && Model.Any()) diff --git a/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs index 85a40d8..683f00a 100644 --- a/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs @@ -24,7 +24,7 @@ namespace UniversityContracts.BusinessLogicContracts void SavePlanOfStudyToWord(ReportBindingModel option); void SaveTeachersToExcel(ReportBindingModel option); void SavePlanOfStudyToExcel(ReportBindingModel option); - void SendDisciplinesToEmail(ReportDateRangeBindingModel option, string email); + void SendDisciplinesToEmail(ReportDateRangeBindingModel option); public void SendPlanOfStudyToEmail(ReportBindingModel option); } } diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 3eebb86..07213d0 100644 --- a/University/UniversityDatabaseImplement/UniversityDatabase.cs +++ b/University/UniversityDatabaseImplement/UniversityDatabase.cs @@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement if (optionsBuilder.IsConfigured == false) { //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR - optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-DYCTATOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/University/UniversityRestApi/Controllers/DisciplineController .cs b/University/UniversityRestApi/Controllers/DisciplineController .cs index 3939318..da19bd7 100644 --- a/University/UniversityRestApi/Controllers/DisciplineController .cs +++ b/University/UniversityRestApi/Controllers/DisciplineController .cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using UniversityBusinessLogic.MailWorker; using UniversityContracts.BindingModels; using UniversityContracts.BusinessLogicContracts; using UniversityContracts.BusinessLogicsContracts; @@ -14,11 +15,13 @@ namespace UniversityRestApi.Controllers private readonly ILogger _logger; private readonly IDisciplineLogic _logic; private readonly IReportLogic _reportLogic; - public DisciplineController(IDisciplineLogic logic, ILogger logger, IReportLogic reportLogic) + private readonly AbstractMailWorker _mailWorker; + public DisciplineController(IDisciplineLogic logic, ILogger logger, IReportLogic reportLogic, AbstractMailWorker mailWorker) { _logic = logic; _logger = logger; _reportLogic = reportLogic; + _mailWorker = mailWorker; } [HttpGet] public List? GetDisciplines(int userId) @@ -99,6 +102,35 @@ namespace UniversityRestApi.Controllers throw; } } + + + [HttpPost] + public void CreateReportToPDFFile(ReportDateRangeBindingModel model) + { + try + { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + _reportLogic.SendDisciplinesToEmail(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + [HttpPost] + public void SendPDFToMail(MailSendInfoBindingModel model) + { + try + { + _mailWorker.MailSendAsync(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отправки письма"); + throw; + } + } } }