This commit is contained in:
Jonathan Jenne
2023-11-20 16:42:11 +01:00
parent 624266a971
commit 56688d2690
18 changed files with 305 additions and 59 deletions

View File

@@ -7,10 +7,12 @@ namespace EnvelopeGenerator.Web.Controllers
public class EnvelopeController : BaseController
{
private readonly EnvelopeService envelopeService;
private readonly EmailService emailService;
public EnvelopeController(DatabaseService database, LoggingService logging, EnvelopeService envelope) : base(database, logging)
public EnvelopeController(DatabaseService database, LoggingService logging, EnvelopeService envelope, EmailService email) : base(database, logging)
{
envelopeService = envelope;
emailService = email;
}
[HttpGet]
@@ -58,6 +60,10 @@ namespace EnvelopeGenerator.Web.Controllers
Status = Common.Constants.DocumentStatus.Signed
});
envelopeService.InsertHistoryEntrySigned(response);
SendSignedEmail(response);
return Ok();
}
catch (Exception e)
@@ -65,5 +71,18 @@ namespace EnvelopeGenerator.Web.Controllers
return ErrorResponse(e);
}
}
public bool SendSignedEmail(EnvelopeResponse response)
{
EmailTemplate template = new();
EmailData emailData = new(response.Envelope, response.Receiver)
{
SignatureLink = "",
};
template.FillDocumentSignedEmailBody(emailData);
return emailService.SendEmail(emailData);
}
}
}

View File

@@ -7,7 +7,7 @@ namespace EnvelopeGenerator.Web.Controllers
{
public class ActionObject
{
public string? ActionType { get; set; }
public int ActionType { get; set; }
}
public class HistoryController : BaseController
@@ -25,18 +25,12 @@ namespace EnvelopeGenerator.Web.Controllers
{
try
{
logger.Info("EnvelopeController/Get");
logger.Info("HistoryController/Post");
// Validate Envelope Key and load envelope
envelopeService.EnsureValidEnvelopeKey(envelopeKey);
EnvelopeResponse response = envelopeService.LoadEnvelope(envelopeKey);
string actionTypeString = action.ActionType;
if (!Enum.TryParse<EnvelopeHistoryActionType>(actionTypeString, out var actionType))
{
return BadRequest();
};
EnvelopeHistoryActionType actionType = (EnvelopeHistoryActionType)action.ActionType;
envelopeService.InsertHistoryEntry(new EnvelopeHistoryEntry()
{

View File

@@ -11,6 +11,7 @@ namespace EnvelopeGenerator.Web
// Add base services
builder.Services.AddSingleton<LoggingService>();
builder.Services.AddTransient<DatabaseService>();
builder.Services.AddTransient<EmailService>();
// Add higher order services
builder.Services.AddSingleton<EnvelopeService>();

View File

@@ -15,6 +15,8 @@ namespace EnvelopeGenerator.Web.Services
public ElementModel elementModel;
public HistoryModel historyModel;
public DocumentStatusModel documentStatusModel;
public EmailModel emailModel;
public ConfigModel configModel;
public ModelContainer(State state)
{
@@ -24,6 +26,8 @@ namespace EnvelopeGenerator.Web.Services
elementModel = new(state);
historyModel = new(state);
documentStatusModel = new(state);
emailModel = new(state);
configModel = new(state);
}
}
public readonly ModelContainer? Models;
@@ -39,8 +43,17 @@ namespace EnvelopeGenerator.Web.Services
{
logger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
// There is a circular dependency between state and models
// All models need a state object, including the config Model
// The state object needs to be filled with the DbConfig property,
// which is obtained by the config Model.
// So first, the config model is initialized with an incomplete state object,
// then all the other models with the DbConfig property filled.
var state = GetState();
Models = new(state);
var configModel = new ConfigModel(state);
state.DbConfig = configModel.LoadConfiguration();
Models = new(state);
}
else
{

View File

@@ -0,0 +1,38 @@
using EnvelopeGenerator.Common;
namespace EnvelopeGenerator.Web.Services
{
public class EmailService : BaseService
{
private ReceiverModel receiverModel;
private EnvelopeModel envelopeModel;
private HistoryModel historyModel;
private DocumentModel documentModel;
private DocumentStatusModel documentStatusModel;
private EmailModel emailModel;
public EmailService(IConfiguration Config, LoggingService Logging, DatabaseService database) : base(Config, Logging)
{
logger = Logging.LogConfig.GetLogger();
if (database.Models == null)
{
throw new ArgumentNullException("Models not loaded.");
}
receiverModel = database.Models.receiverModel;
envelopeModel = database.Models.envelopeModel;
historyModel = database.Models.historyModel;
documentModel = database.Models.documentModel;
documentStatusModel = database.Models.documentStatusModel;
emailModel = database.Models.emailModel;
}
public bool SendEmail(EmailData emailData)
{
return emailModel.Insert(emailData);
}
}
}

View File

@@ -101,23 +101,9 @@
return annotation
}
async createFrameAnnotation(annotation, receiver) {
const left = annotation.boundingBox.left - 25
const top = annotation.boundingBox.top - 25
const width = 150
const height = 75
const imageUrl = await this.Annotation.createAnnotationFrameBlob(
receiver.name,
width,
height
)
const request = await fetch(imageUrl)
const blob = await request.blob()
const imageAttachmentId = await this.Instance.createAttachment(blob)
createImageAnnotation(boundingBox, pageIndex, imageAttachmentId) {
const frameAnnotation = new PSPDFKit.Annotations.ImageAnnotation({
pageIndex: annotation.pageIndex,
pageIndex: pageIndex,
isSignature: false,
readOnly: true,
locked: true,
@@ -125,13 +111,9 @@
contentType: 'image/png',
imageAttachmentId,
description: 'FRAME',
boundingBox: new PSPDFKit.Geometry.Rect({
left: left,
top: top,
width: width,
height: height,
}),
})
boundingBox: boundingBox,
});
return frameAnnotation
}
async createAnnotationFrameBlob(receiverName, width, height) {

View File

@@ -93,10 +93,26 @@ class App {
const isSignature = !!annotation.isSignature
if (isFormField === false && isSignature === true) {
await this.Annotation.createFrameAnnotation(
annotation,
this.currentReceiver
)
const left = annotation.boundingBox.left - 25;
const top = annotation.boundingBox.top - 25;
const width = 150;
const height = 75;
const imageUrl = await this.Annotation.createAnnotationFrameBlob(this.currentReceiver.name, width, height);
const request = await fetch(imageUrl);
const blob = await request.blob();
const imageAttachmentId = await this.Instance.createAttachment(blob);
const frameAnnotation = this.Annotation.createImageAnnotation(new PSPDFKit.Geometry.Rect({
left: left,
top: top,
width: width,
height: height,
}), annotation.pageIndex, imageAttachmentId)
this.Instance.create(frameAnnotation);
}
}
@@ -119,8 +135,8 @@ class App {
result = await this.handleFinish(null)
if (result == true) {
// TODO: Redirect to success page
alert('Dokument erfolgreich signiert!')
// Redirect to success page after saving to database
window.location.href = `/EnvelopeKey/${this.envelopeKey}/Success`
} else {
alert('Fehler beim Abschließen des Dokuments!')
}
@@ -147,12 +163,11 @@ class App {
JSON.stringify(json)
)
console.log(postEnvelopeResult)
if (postEnvelopeResult === false) {
return false
}
// Redirect to success page after saving to database
window.location.href = `/EnvelopeKey/${this.envelopeKey}/Success`
} catch (e) {
console.error(e)
return false

View File

@@ -39,6 +39,8 @@
actionType: actionType,
}
console.log(data)
const options = {
credentials: 'include',
method: 'POST',