61 lines
1.9 KiB
C#
61 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();
|
|
}
|
|
// Generates and returns a Tar Ball Sampling Report PDF
|
|
public IActionResult GenerateReport()
|
|
{
|
|
try
|
|
{
|
|
var document = new TarBallPDF();
|
|
var pdf = document.GeneratePdf();
|
|
var fileName = $"TarBallReport_{DateTime.Now:yyyyMMdd_HHmmss}.pdf";
|
|
return File(pdf, "application/pdf", fileName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// Log the error (use a logger if configured)
|
|
Console.WriteLine(ex.Message);
|
|
return StatusCode(StatusCodes.Status500InternalServerError, "An error occurred while generating the PDF. "+ex.Message);
|
|
}
|
|
}
|
|
|
|
public IActionResult ViewPDF()
|
|
{
|
|
try
|
|
{
|
|
// Generate the PDF document
|
|
var document = new TarBallPDF();
|
|
var pdf = document.GeneratePdf();
|
|
|
|
// Return the PDF for inline viewing
|
|
return File(pdf, "application/pdf");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// Log the error (use a logger if configured)
|
|
Console.WriteLine(ex.Message);
|
|
return StatusCode(StatusCodes.Status500InternalServerError, "An error occurred while viewing the PDF. " + ex.Message);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|