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
|
||||
|
||||
Reference in New Issue
Block a user