CourseWork_CompShop/ComputerShopProvider/ComputerShopRestApi/Controllers/ReportController.cs
2023-05-24 21:41:02 +04:00

80 lines
2.2 KiB
C#

using ComputerShopContracts.BindingModels;
using ComputerShopContracts.SearchModels;
using ComputerShopContracts.ViewModels;
using ComputerShopBusinessLogic.BusinessLogics;
using Microsoft.AspNetCore.Mvc;
using ComputerShopContracts.BusinessLogicContracts;
using ComputerShopBusinessLogic.MailWorker;
[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 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;
}
}
[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;
}
}
[HttpPost]
public void SendPdfToMail(MailSendInfoBindingModel model)
{
try
{
_mailWorker.MailSendAsync(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отправки письма");
throw;
}
}
}