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; + } + } } }