102 lines
2.8 KiB
C#
102 lines
2.8 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Reporting.NETCore;
|
|
using NLog;
|
|
using WebDoorCreator.Data.Services;
|
|
|
|
namespace WebDoorCreator.API.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class ReportController : ControllerBase
|
|
{
|
|
#region Public Constructors
|
|
|
|
public ReportController(IConfiguration configuration, QueueDataService DataService)
|
|
{
|
|
Log.Info("Starting ReportController");
|
|
_configuration = configuration;
|
|
QDataServ = DataService;
|
|
Log.Info("Avviato ReportController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
// GET: api/Alive
|
|
[HttpGet]
|
|
public string Get()
|
|
{
|
|
return "OK";
|
|
}
|
|
|
|
[HttpGet("GetReport")]
|
|
public async Task<IActionResult> GetReport(int OrderId, string Format)
|
|
{
|
|
await Task.Delay(1);
|
|
string Extension = "";
|
|
string MimeType = "";
|
|
switch (Format.ToUpper())
|
|
{
|
|
case "HTML5":
|
|
Extension = "html";
|
|
MimeType = "text/html";
|
|
break;
|
|
|
|
case "WORDOPENXML":
|
|
Extension = "docx";
|
|
MimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
break;
|
|
|
|
case "EXCELOPENXML":
|
|
Extension = "xlsx";
|
|
MimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
break;
|
|
|
|
case "PDF":
|
|
default:
|
|
Extension = "pdf";
|
|
MimeType = "application/pdf";
|
|
break;
|
|
}
|
|
// restituisco oggetto
|
|
return PrepareReport(Format, Extension, MimeType);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration = null!;
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private decimal GizmoPrice { get; set; }
|
|
|
|
private QueueDataService QDataServ { get; set; } = null!;
|
|
|
|
private decimal WidgetPrice { get; set; }
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private IActionResult PrepareReport(string renderFormat, string extension, string mimeType)
|
|
{
|
|
using var report = new LocalReport();
|
|
|
|
WidgetPrice = 104.99m;
|
|
GizmoPrice = 1.41m;
|
|
|
|
Core.ReportViewer.Report.Load(report, WidgetPrice, GizmoPrice);
|
|
var pdf = report.Render(renderFormat);
|
|
return File(pdf, mimeType, "report." + extension);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |