TekH 6f73ba929c Refactor controllers and update envelope status handling
- Updated `TestEnvelopeHistoryController` to use `EnvelopeStatus` for status parameters and marked it as obsolete.
- Modified `TestViewController` with new route attributes, simplified constructor, and improved error handling in HTTP methods.
- Cleaned up `DebugEnvelopes.cshtml` by removing unnecessary using directives and ensuring type safety in envelope grouping.
2025-06-27 13:51:51 +02:00

55 lines
1.6 KiB
C#

using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.Web.Services;
using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Web.Controllers.Test;
[Route("api/test/[controller]")]
public class TestViewController : BaseController
{
private readonly EnvelopeOldService envelopeOldService;
private readonly IConfiguration _config;
public TestViewController(DatabaseService databaseService, EnvelopeOldService envelopeOldService, ILogger<TestViewController> logger, IConfiguration configuration) : base(databaseService, logger)
{
this.envelopeOldService = envelopeOldService;
_config = configuration;
}
[HttpGet]
public IActionResult Index()
{
return View("AnnotationIndex");
}
[HttpPost]
public IActionResult DebugEnvelopes([FromForm] string? password)
{
try
{
var passwordFromConfig = _config["AdminPassword"];
if (passwordFromConfig == null)
{
ViewData["error"] = "No admin password configured!";
return View("AnnotationIndex");
}
if (password != passwordFromConfig)
{
ViewData["error"] = "Wrong Password!";
return View("AnnotationIndex");
}
List<Envelope> envelopes = envelopeOldService.LoadEnvelopes();
return View("DebugEnvelopes", envelopes);
}
catch(Exception ex)
{
_logger.LogError(ex, "Unexpected error");
ViewData["error"] = "Unknown error!";
return View("AnnotationIndex");
}
}
}