03-11-2023
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
using DigitalData.Modules.Logging;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using DigitalData.Modules.Logging;
|
||||
using EnvelopeGenerator.Common;
|
||||
using EnvelopeGenerator.Web.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Reflection.Metadata;
|
||||
using static EnvelopeGenerator.Web.Handler.FileHandler;
|
||||
using static EnvelopeGenerator.Common.Constants;
|
||||
using static EnvelopeGenerator.Web.Constants;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
@@ -24,15 +24,16 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
|
||||
[HttpGet]
|
||||
[Route("api/document/{envelopeKey}")]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public async Task<IActionResult> Get(string envelopeKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("Handling file download.");
|
||||
|
||||
// Validate Envelope Key
|
||||
EnvelopeResponse r = api.EnsureValidEnvelopeKey(envelopeKey);
|
||||
|
||||
// Load document info
|
||||
var Request = ControllerContext.HttpContext.Request;
|
||||
var document = api.GetDocument(Request, envelopeKey);
|
||||
|
||||
@@ -43,6 +44,15 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
// Return the document as bytes
|
||||
return File(bytes, "application/octet-stream");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.Error(e);
|
||||
return Problem(
|
||||
statusCode: 500,
|
||||
detail: e.Message,
|
||||
type: ErrorType.ServerError.ToString());
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Better error handling & reporting
|
||||
@@ -57,25 +67,46 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/document/{envelopeKey}")]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public async Task<IActionResult> Update(string envelopeKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("Handling file update.");
|
||||
|
||||
api.EnsureValidEnvelopeKey(envelopeKey);
|
||||
// Validate Envelope Key
|
||||
EnvelopeResponse r = api.EnsureValidEnvelopeKey(envelopeKey);
|
||||
|
||||
// Load Document info
|
||||
var Request = ControllerContext.HttpContext.Request;
|
||||
var document = api.GetDocument(Request, envelopeKey);
|
||||
|
||||
// Try to update the document with new data
|
||||
if (!await api.UpdateDocument(Request.Body, document.Filepath))
|
||||
{
|
||||
throw new IOException("Document could not be saved to disk!");
|
||||
}
|
||||
|
||||
// Add history entry
|
||||
database.InsertHistoryEntry(new EnvelopeHistoryEntry()
|
||||
{
|
||||
ActionDescription = "Dokument wurde signiert",
|
||||
ActionDate = DateTime.Now,
|
||||
ActionType = EnvelopeHistoryActionType.Signed,
|
||||
EnvelopeId = r.Envelope.Id,
|
||||
UserReference = r.Receiver.Email
|
||||
});
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.Error(e);
|
||||
return Problem(
|
||||
statusCode: 500,
|
||||
detail: e.Message,
|
||||
type: ErrorType.ServerError.ToString());
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Better error handling & reporting
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using EnvelopeGenerator.Common;
|
||||
using DigitalData.Modules.Logging;
|
||||
using EnvelopeGenerator.Common;
|
||||
using EnvelopeGenerator.Web.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NLog;
|
||||
using static EnvelopeGenerator.Web.Handler.FileHandler;
|
||||
using static EnvelopeGenerator.Web.Constants;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
@@ -23,7 +24,6 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
|
||||
[HttpGet]
|
||||
[Route("api/envelope/{envelopeKey}")]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public IActionResult Get(string envelopeKey)
|
||||
{
|
||||
try
|
||||
@@ -50,16 +50,13 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/envelope/{envelopeKey}")]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public async Task<IActionResult> Update(string envelopeKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("Handling envelope saving.");
|
||||
|
||||
api.EnsureValidEnvelopeKey(envelopeKey);
|
||||
|
||||
EnvelopeResponse r = database.LoadEnvelope(envelopeKey);
|
||||
EnvelopeResponse r = api.EnsureValidEnvelopeKey(envelopeKey);
|
||||
|
||||
var Request = ControllerContext.HttpContext.Request;
|
||||
var document = api.GetDocument(Request, envelopeKey);
|
||||
@@ -71,13 +68,10 @@ namespace EnvelopeGenerator.Web.Controllers
|
||||
throw new ArgumentNullException("AnnotationData");
|
||||
}
|
||||
|
||||
State state = api.GetState(logging.LogConfig, database.MSSQL);
|
||||
DocumentStatusModel model = new(state);
|
||||
|
||||
model.InsertOrUpdate(new DocumentStatus()
|
||||
database.InsertDocumentStatus(new DocumentStatus()
|
||||
{
|
||||
EnvelopeId = r.Envelope.Id,
|
||||
ReceiverId = r.ReceiverId,
|
||||
ReceiverId = r.Receiver.Id,
|
||||
Value = annotationData,
|
||||
Status = Common.Constants.DocumentStatus.Signed
|
||||
});
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
using DigitalData.Modules.Logging;
|
||||
using EnvelopeGenerator.Common;
|
||||
using EnvelopeGenerator.Web.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using static EnvelopeGenerator.Common.Constants;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
public class HistoryController : Controller
|
||||
{
|
||||
private readonly DatabaseService database;
|
||||
private readonly LoggingService logging;
|
||||
private readonly Logger logger;
|
||||
private readonly ApiService api;
|
||||
|
||||
public HistoryController(DatabaseService database, LoggingService logging, ApiService api)
|
||||
{
|
||||
this.database = database;
|
||||
this.logging = logging;
|
||||
this.logger = logging.LogConfig.GetLoggerFor(GetType().Name);
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/history/{envelopeKey}")]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public IActionResult Create(string envelopeKey, [FromBody] ActionObject action)
|
||||
{
|
||||
try
|
||||
{
|
||||
var Request = ControllerContext.HttpContext.Request;
|
||||
|
||||
api.EnsureValidEnvelopeKey(envelopeKey);
|
||||
EnvelopeResponse r = database.LoadEnvelope(envelopeKey);
|
||||
var receiver = r.Envelope.Receivers.Where(receiver => receiver.Id == r.ReceiverId).SingleOrDefault();
|
||||
|
||||
if (receiver == null)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
string actionTypeString = action.actionType;
|
||||
string actionDescription = action.actionDescription;
|
||||
|
||||
if (!Enum.TryParse<EnvelopeHistoryActionType>(actionTypeString, out var actionType))
|
||||
{
|
||||
return BadRequest();
|
||||
};
|
||||
|
||||
database.InsertHistoryEntry(new EnvelopeHistoryEntry()
|
||||
{
|
||||
ActionDescription = actionDescription,
|
||||
ActionDate = DateTime.Now,
|
||||
ActionType = actionType,
|
||||
EnvelopeId = r.Envelope.Id,
|
||||
UserReference = receiver.Email
|
||||
});
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error(e);
|
||||
return Problem(statusCode: 500);
|
||||
}
|
||||
}
|
||||
|
||||
public class ActionObject
|
||||
{
|
||||
public string actionType { get; set; }
|
||||
public string actionDescription { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user