85 lines
2.4 KiB
C#
85 lines
2.4 KiB
C#
using HospitalBusinessLogic.MailWorker;
|
|
using HospitalContracts.BindingModels;
|
|
using HospitalContracts.BusinessLogicsContracts;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace HospitalRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class ReportController : Controller
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IReportLogic _reportLogic;
|
|
private readonly AbstractMailWorker _mailWorker;
|
|
public ReportController(ILogger<ReportController> logger, IReportLogic reportLogic, AbstractMailWorker mailWorker)
|
|
{
|
|
_logger = logger;
|
|
_reportLogic = reportLogic;
|
|
_mailWorker = mailWorker;
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CreateReportToPdfFile(ReportBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_reportLogic.SaveRecipesToPdfFile(new ReportBindingModel
|
|
{
|
|
DateFrom = model.DateFrom,
|
|
DateTo = model.DateTo,
|
|
ClientId = model.ClientId,
|
|
FileName = "E:\\ReportsCourseWork\\pdffile.pdf",
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void SendPdfToMail(MailSendInfoBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_mailWorker.MailSendAsync(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка отправки письма");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CreateReportToWordFile(ReportBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_reportLogic.SaveMedicinesToWordFile(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CreateReportToExcelFile(ReportBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_reportLogic.SaveMedicinesToExcelFile(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания отчета");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|