сделал контроллер репортов

This commit is contained in:
Katanaa Die 2024-05-29 18:17:56 +04:00
parent 070ab07e7f
commit 9c3c48983d

View File

@ -0,0 +1,88 @@
using Microsoft.AspNetCore.Mvc;
using VetclinicBusinessLogic.BusinessLogics;
using VetclinicBusinessLogic.MailWorker;
using VetclinicContracts.BindingModels;
using VetclinicContracts.BusinessLogicsContracts;
using VetclinicContracts.ViewModels;
namespace VetclinicRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ReportController : Controller
{
private readonly IReportLogicDoctor _reportDoctor;
private readonly AbstractMailWorker _mailWorker;
public ReportController(ILogger<ReportController> logger, IReportLogicDoctor reportDoctor, AbstractMailWorker mailWorker)
{
_reportDoctor = reportDoctor;
_mailWorker = mailWorker;
}
[Microsoft.AspNetCore.Mvc.HttpGet]
public IActionResult Index(ReportLogicDoctor reportDoctor)
{
return View();
}
[HttpPost]
public void CreatePurchaseListWordFile(ReportPurchaseMedicineBindingModel model)
{
try
{
_reportDoctor.SavePurchasesToWordFile(model);
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void CreatePurchaseListExcelFile(ReportPurchaseMedicineBindingModel model)
{
try
{
_reportDoctor.SavePurchasesToExcelFile(model);
}
catch (Exception ex)
{
throw;
}
}
[HttpGet]
public List<ReportDrugsVisitsViewModel> GetDrugsVisitsReport(string dateFrom, string dateTo, int doctorId)
{
try
{
DateTime DateFrom = DateTime.Parse(dateFrom);
DateTime DateTo = DateTime.Parse(dateTo);
ReportDrugsVisitsBindingModel model = new();
model.DateFrom = DateFrom;
model.DateTo = DateTo;
model.DoctorId = doctorId;
return _reportDoctor.GetVisitsDrugs(model);
}
catch (Exception ex)
{
throw;
}
}
[HttpPost]
public void SendDrugsVisitsReportToEmail(ReportDrugsVisitsBindingModel model)
{
try
{
_reportDoctor.SaveMedicinesToPdfFile(model);
_mailWorker.MailSendAsync(new MailSendInfoBindingModel
{
MailAddress = model.Email!,
Subject = "Отчет по медикаментам",
Text = "Лови"
});
}
catch (Exception ex)
{
throw;
}
}
}
}