PIbd-21_CourseWork_Polyclin.../Polyclinic/PolyclinicWebAppImplementer/Controllers/ReportsController.cs

82 lines
2.6 KiB
C#

using Microsoft.AspNetCore.Mvc;
using PolyclinicBusinessLogic.OfficePackage.HelperEnums;
using PolyclinicContracts.BindingModels;
using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.ViewModels;
using PolyclinicWebAppImplementer.Models;
namespace PolyclinicWebAppImplementer.Controllers
{
public class ReportsController : Controller
{
private readonly IImplementerReportLogic _reportLogic;
private readonly IDiagnoseLogic _diagnoseLogic;
public ReportsController(IImplementerReportLogic reportLogic, IDiagnoseLogic diagnoseLogic)
{
_reportLogic = reportLogic;
_diagnoseLogic = diagnoseLogic;
}
[HttpGet]
[HttpPost]
public IActionResult DiagnosesByPeriod(DiagnosesByPeriodFormModel model)
{
var currentUser = LoginManager.LogginedUser;
if (currentUser == null)
{
return RedirectToAction("Login", "User");
}
if (HttpContext.Request.Method == "GET")
{
return View(model);
}
else
{
var report = _reportLogic.GetReportDiagnosesByPeriod(model.DateStart, model.DateEnd);
if (model.ReportType == ReportType.Web)
{
model.Report = report;
}
else
{
ReportBindingModel reportInfo = new()
{
FileName = "diagnosesByPeriod.pdf",
DateFrom = model.DateStart,
DateTo = model.DateEnd
};
_reportLogic.SaveReportDiagnosesByPeriodToPdfFile(reportInfo, report);
var fileName = reportInfo.FileName;
var filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
return File(fileBytes, "application/pdf", fileName);
}
return View(model);
}
}
[HttpGet]
[HttpPost]
public IActionResult MedicamentsByDiagnoses(MedicamentsByDiagnosesFormModel model)
{
var currentUser = LoginManager.LogginedUser;
if (currentUser == null)
{
return RedirectToAction("Login", "User");
}
if (HttpContext.Request.Method == "GET")
{
return View(model);
}
else
{
return View(model);
}
}
}
}