56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
using EnvelopeGenerator.Application.Contracts;
|
|
using EnvelopeGenerator.Common;
|
|
using EnvelopeGenerator.Web.Services;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace EnvelopeGenerator.Web.Controllers.Test
|
|
{
|
|
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("Index");
|
|
}
|
|
|
|
[HttpPost("/")]
|
|
public IActionResult DebugEnvelopes([FromForm] string? password)
|
|
{
|
|
try
|
|
{
|
|
var passwordFromConfig = _config["Config:AdminPassword"];
|
|
|
|
if (passwordFromConfig == null)
|
|
{
|
|
ViewData["error"] = "No admin password configured!";
|
|
return View("Index");
|
|
}
|
|
|
|
if (password != passwordFromConfig)
|
|
{
|
|
ViewData["error"] = "Wrong Password!";
|
|
return View("Index");
|
|
}
|
|
|
|
List<Envelope> envelopes = envelopeOldService.LoadEnvelopes();
|
|
|
|
return View("DebugEnvelopes", envelopes);
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Unexpected error");
|
|
ViewData["error"] = "Unknown error!";
|
|
return View("Index");
|
|
}
|
|
}
|
|
}
|
|
} |