PSTW_CentralizeSystem/Areas/MMS/Controllers/MarineController.cs

58 lines
1.9 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PSTW_CentralSystem.Areas.MMS;
using QuestPDF.Fluent;
namespace PSTW_CentralSystem.Areas.MMS.Controllers
{
[Area("MMS")]
//[Authorize(Policy = "RoleModulePolicy")]
public class MarineController : Controller
{
public IActionResult Index()
{
return View(); // This will look for Index.cshtml in Areas/MMS/Views/Marine
}
public IActionResult TarBallForm()
{
return View();
}
public IActionResult GenerateReport()
{
try
{
// Retrieve specific data based on the id, if required
var document = new TarBallPDF(); // Use id to customize the report if needed
var pdf = document.GeneratePdf();
var fileName = $"TarBallReport_{DateTime.Now:yyyyMMdd_HHmmss}.pdf";
return File(pdf, "application/pdf", fileName);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, "An error occurred while generating the PDF. " + ex.Message);
}
}
public IActionResult ViewPDF()
{
try
{
// Retrieve specific data based on the id, if required
var document = new TarBallPDF(); // Use id to customize the PDF if needed
var pdf = document.GeneratePdf();
return File(pdf, "application/pdf");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return StatusCode(StatusCodes.Status500InternalServerError, "An error occurred while viewing the PDF. " + ex.Message);
}
}
}
}