- Notwendige Repositories, Services und DTOs für jede Entität, die SQL-Tabellen entspricht, unter Verwendung der WebCore-Bibliothek erstellt. - Mapping-Profile für effiziente Datentransformation definiert. - Dependency Injections für Repositories und Services als scoped konfiguriert, um eine korrekte Lebenszyklusverwaltung zu gewährleisten.
143 lines
5.0 KiB
C#
143 lines
5.0 KiB
C#
using EnvelopeGenerator.Common;
|
|
using EnvelopeGenerator.Web.Models;
|
|
using EnvelopeGenerator.Web.Services;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Primitives;
|
|
using System.Diagnostics;
|
|
|
|
namespace EnvelopeGenerator.Web.Controllers
|
|
{
|
|
public class HomeController : BaseController
|
|
{
|
|
private readonly EnvelopeOldService _envelopeService;
|
|
private readonly IConfiguration _config;
|
|
|
|
public HomeController(DatabaseService databaseService, EnvelopeOldService envelopeService, ILogger<HomeController> logger, IConfiguration configuration) : base(databaseService, logger)
|
|
{
|
|
_envelopeService = envelopeService;
|
|
_config = configuration;
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("/")]
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("/")]
|
|
public IActionResult DebugEnvelopes([FromForm] string password)
|
|
{
|
|
try
|
|
{
|
|
var passwordFromConfig = _config["Config:AdminPassword"] ?? throw new InvalidOperationException("No admin password configured!");
|
|
|
|
if (passwordFromConfig == null)
|
|
{
|
|
ViewData["error"] = "No admin password configured!";
|
|
return View("Index");
|
|
}
|
|
|
|
if (password == null)
|
|
{
|
|
ViewData["error"] = "No password supplied!";
|
|
return View("Index");
|
|
}
|
|
|
|
if (password != passwordFromConfig)
|
|
{
|
|
ViewData["error"] = "Wrong Password!";
|
|
return View("Index");
|
|
}
|
|
|
|
List<Envelope> envelopes = _envelopeService.LoadEnvelopes();
|
|
|
|
return View(envelopes);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
ViewData["error"] = "Unknown error!";
|
|
return View("Index");
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("/EnvelopeKey/{envelopeReceiverId}")]
|
|
public async Task<IActionResult> ShowEnvelope([FromRoute] string envelopeReceiverId)
|
|
{
|
|
EnvelopeResponse response = await _envelopeService.LoadEnvelope(envelopeReceiverId);
|
|
|
|
if (response.Envelope.UseAccessCode)
|
|
{
|
|
bool accessCodeAlreadyRequested = database.Models.receiverModel.AccessCodeAlreadyRequested(response.Receiver.Email, response.Envelope.Id);
|
|
|
|
if (!accessCodeAlreadyRequested)
|
|
{
|
|
// Send email with password
|
|
bool actionResult = database.Services.actionService.RequestAccessCode(response.Envelope, response.Receiver);
|
|
bool result = database.Services.emailService.SendDocumentAccessCodeReceivedEmail(response.Envelope, response.Receiver);
|
|
}
|
|
|
|
return Redirect($"/EnvelopeKey/{envelopeReceiverId}/Locked");
|
|
}
|
|
else
|
|
{
|
|
ViewData["EnvelopeKey"] = envelopeReceiverId;
|
|
return View();
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("/EnvelopeKey/{envelopeReceiverId}/Locked")]
|
|
public async Task<IActionResult> ShowEnvelopePost([FromRoute] string envelopeReceiverId, [FromForm] string access_code)
|
|
{
|
|
EnvelopeResponse response = await _envelopeService.LoadEnvelope(envelopeReceiverId);
|
|
string accessCode = response.Receiver.AccessCode;
|
|
|
|
if (string.IsNullOrEmpty(access_code))
|
|
{
|
|
return Redirect($"/EnvelopeKey/{envelopeReceiverId}/Locked");
|
|
}
|
|
|
|
if (accessCode == access_code)
|
|
{
|
|
bool actionResult = database.Services.actionService.EnterCorrectAccessCode(response.Envelope, response.Receiver);
|
|
ViewData["EnvelopeKey"] = envelopeReceiverId;
|
|
return View("ShowEnvelope");
|
|
}
|
|
else
|
|
{
|
|
bool actionResult = database.Services.actionService.EnterIncorrectAccessCode(response.Envelope, response.Receiver);
|
|
return Redirect($"/EnvelopeKey/{envelopeReceiverId}/Locked");
|
|
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("/EnvelopeKey/{envelopeReceiverId}/Locked")]
|
|
public IActionResult EnvelopeLocked([FromRoute] string envelopeReceiverId)
|
|
{
|
|
ViewData["EnvelopeKey"] = envelopeReceiverId;
|
|
return View();
|
|
}
|
|
|
|
|
|
|
|
[HttpGet]
|
|
[Route("/EnvelopeKey/{EnvelopeReceiverId}/Success")]
|
|
public IActionResult EnvelopeSigned()
|
|
{
|
|
ViewData["EnvelopeKey"] = HttpContext.Request.RouteValues["EnvelopeReceiverId"];
|
|
|
|
return View();
|
|
}
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
}
|
|
} |