CourseWork_CompShop/ComputerShopProvider/ComputerShopRestApi/Controllers/ReportController.cs

80 lines
2.2 KiB
C#
Raw Permalink Normal View History

2023-05-18 22:18:40 +04:00
using ComputerShopContracts.BindingModels;
using ComputerShopContracts.SearchModels;
using ComputerShopContracts.ViewModels;
using ComputerShopBusinessLogic.BusinessLogics;
using Microsoft.AspNetCore.Mvc;
using ComputerShopContracts.BusinessLogicContracts;
2023-05-24 21:41:02 +04:00
using ComputerShopBusinessLogic.MailWorker;
2023-05-18 22:18:40 +04:00
[Route("api/[controller]/[action]")]
[ApiController]
public class ReportController : Controller
{
private readonly ILogger _logger;
private readonly IReportLogic _reportLogic;
2023-05-24 21:41:02 +04:00
private readonly AbstractMailWorker _mailWorker;
public ReportController(ILogger<ReportController> logger, IReportLogic reportLogic, AbstractMailWorker mailWorker)
2023-05-18 22:18:40 +04:00
{
_logger = logger;
_reportLogic = reportLogic;
2023-05-24 21:41:02 +04:00
_mailWorker = mailWorker;
2023-05-18 22:18:40 +04:00
}
[HttpPost]
public void CreateDocReport(ReportBindingModel model)
{
try
{
_reportLogic.SaveReceivingComponentsToWordFile(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
[HttpPost]
public void CreateXmlReport(ReportBindingModel model)
{
try
{
_reportLogic.SaveReceivingComponentsToXmlFile(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
2023-05-24 21:14:10 +04:00
[HttpPost]
public void CreatePdfReport(ReportBindingModel model)
{
try
{
_reportLogic.SavePurchaseSuppliesToPdfFile(new ReportBindingModel
{
DateFrom = model.DateFrom,
DateTo = model.DateTo,
FileName = "F:\\ReportsCourseWork\\pdffile.pdf",
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
2023-05-24 21:41:02 +04:00
[HttpPost]
public void SendPdfToMail(MailSendInfoBindingModel model)
{
try
{
_mailWorker.MailSendAsync(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отправки письма");
throw;
}
}
2023-05-18 22:18:40 +04:00
}