Отправка на почту пдф

This commit is contained in:
GokaPek 2024-05-30 00:31:58 +04:00
parent 2c4de39d60
commit 3226311dd2
6 changed files with 71 additions and 15 deletions

View File

@ -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, FileName = option.FileName,
Title = "Отчёт по дисциплинам", Title = "Отчёт по дисциплинам",
PlanOfStudyAndStudent = GetPlanOfStudyAndStudents() Disciplines = GetDisciplines(option)
}); });
} }

View File

@ -217,15 +217,32 @@ namespace UniversityClientApp.Controllers
} }
} }
/*[HttpGet] [HttpPost]
public IActionResult ReportDisciplines() public void ReportDisciplines(string type, DateOnly dateFrom, DateOnly dateTo)
{ {
if (APIStorekeeper.Client == null) if (APIStorekeeper.Client == null)
{ {
return Redirect("~/Home/Enter"); Redirect("~/Home/Enter");
} throw new Exception("Âõîä òîëüêî àâòîðèçîâàííûì");
return View(); }
}*/ 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] [HttpGet]
public IActionResult ReportDisciplines(DateOnly dateFrom, DateOnly dateTo) public IActionResult ReportDisciplines(DateOnly dateFrom, DateOnly dateTo)

View File

@ -16,6 +16,13 @@
<div class="row"> <div class="row">
<div class="col-4"><input type="submit" value="Вывести здесь" class="btn btn-primary" /></div> <div class="col-4"><input type="submit" value="Вывести здесь" class="btn btn-primary" /></div>
</div> </div>
</form>
<form method="post" action="/Home/ReportDisciplines">
<input type="hidden" name="type" value="pdf" />
<input type="submit" value="Отправить в формате Pdf на почту" class="btn btn-primary" />
</form> </form>
@if (Model != null && Model.Any()) @if (Model != null && Model.Any())

View File

@ -24,7 +24,7 @@ namespace UniversityContracts.BusinessLogicContracts
void SavePlanOfStudyToWord(ReportBindingModel option); void SavePlanOfStudyToWord(ReportBindingModel option);
void SaveTeachersToExcel(ReportBindingModel option); void SaveTeachersToExcel(ReportBindingModel option);
void SavePlanOfStudyToExcel(ReportBindingModel option); void SavePlanOfStudyToExcel(ReportBindingModel option);
void SendDisciplinesToEmail(ReportDateRangeBindingModel option, string email); void SendDisciplinesToEmail(ReportDateRangeBindingModel option);
public void SendPlanOfStudyToEmail(ReportBindingModel option); public void SendPlanOfStudyToEmail(ReportBindingModel option);
} }
} }

View File

@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
//Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR //Возможно понадобится писать вместо (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); base.OnConfiguring(optionsBuilder);
} }

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using UniversityBusinessLogic.MailWorker;
using UniversityContracts.BindingModels; using UniversityContracts.BindingModels;
using UniversityContracts.BusinessLogicContracts; using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.BusinessLogicsContracts; using UniversityContracts.BusinessLogicsContracts;
@ -14,11 +15,13 @@ namespace UniversityRestApi.Controllers
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IDisciplineLogic _logic; private readonly IDisciplineLogic _logic;
private readonly IReportLogic _reportLogic; private readonly IReportLogic _reportLogic;
public DisciplineController(IDisciplineLogic logic, ILogger<DisciplineController> logger, IReportLogic reportLogic) private readonly AbstractMailWorker _mailWorker;
public DisciplineController(IDisciplineLogic logic, ILogger<DisciplineController> logger, IReportLogic reportLogic, AbstractMailWorker mailWorker)
{ {
_logic = logic; _logic = logic;
_logger = logger; _logger = logger;
_reportLogic = reportLogic; _reportLogic = reportLogic;
_mailWorker = mailWorker;
} }
[HttpGet] [HttpGet]
public List<DisciplineViewModel>? GetDisciplines(int userId) public List<DisciplineViewModel>? GetDisciplines(int userId)
@ -99,6 +102,35 @@ namespace UniversityRestApi.Controllers
throw; 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;
}
}
} }
} }