93 lines
2.8 KiB
C#
93 lines
2.8 KiB
C#
using DigitalData.Modules.Logging;
|
|
using EnvelopeGenerator.Common;
|
|
using EnvelopeGenerator.Web.Services;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using NLog;
|
|
using static EnvelopeGenerator.Web.Constants;
|
|
|
|
namespace EnvelopeGenerator.Web.Controllers
|
|
{
|
|
public class EnvelopeController : Controller
|
|
{
|
|
private readonly DatabaseService database;
|
|
private readonly LoggingService logging;
|
|
private readonly Logger logger;
|
|
private readonly ApiService api;
|
|
|
|
public EnvelopeController(DatabaseService database, LoggingService logging, ApiService api)
|
|
{
|
|
this.database = database;
|
|
this.logging = logging;
|
|
this.logger = logging.LogConfig.GetLoggerFor(GetType().Name);
|
|
this.api = api;
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("api/envelope/{envelopeKey}")]
|
|
public IActionResult Get(string envelopeKey)
|
|
{
|
|
try
|
|
{
|
|
logger.Info("Handling envelope loading.");
|
|
|
|
EnvelopeResponse r = api.EnsureValidEnvelopeKey(envelopeKey);
|
|
|
|
// Return the envelope and additional data as json
|
|
return Json(r);
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// Better error handling & reporting
|
|
logger.Error(e);
|
|
return Problem(
|
|
statusCode: 500,
|
|
detail: e.Message,
|
|
type: ErrorType.ServerError.ToString());
|
|
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("api/envelope/{envelopeKey}")]
|
|
public async Task<IActionResult> Update(string envelopeKey)
|
|
{
|
|
try
|
|
{
|
|
logger.Info("Handling envelope saving.");
|
|
|
|
EnvelopeResponse r = api.EnsureValidEnvelopeKey(envelopeKey);
|
|
|
|
var Request = ControllerContext.HttpContext.Request;
|
|
var document = api.GetDocument(Request, envelopeKey);
|
|
|
|
string? annotationData = await api.EnsureValidAnnotationData(Request);
|
|
|
|
if (annotationData == null)
|
|
{
|
|
throw new ArgumentNullException("AnnotationData");
|
|
}
|
|
|
|
database.InsertDocumentStatus(new DocumentStatus()
|
|
{
|
|
EnvelopeId = r.Envelope.Id,
|
|
ReceiverId = r.Receiver.Id,
|
|
Value = annotationData,
|
|
Status = Common.Constants.DocumentStatus.Signed
|
|
});
|
|
|
|
return Ok();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// Better error handling & reporting
|
|
logger.Error(e);
|
|
return Problem(
|
|
statusCode: 500,
|
|
detail: e.Message,
|
|
type: ErrorType.ServerError.ToString());
|
|
}
|
|
}
|
|
}
|
|
}
|