Jonathan Jenne 3874bc742d 03-11-23
2023-11-13 09:26:48 +01:00

70 lines
2.2 KiB
C#

using EnvelopeGenerator.Common;
using EnvelopeGenerator.Web.Services;
using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Web.Controllers
{
public class EnvelopeController : BaseController
{
private readonly EnvelopeService envelopeService;
public EnvelopeController(DatabaseService database, LoggingService logging, EnvelopeService envelope) : base(database, logging)
{
envelopeService = envelope;
}
[HttpGet]
[Route("api/envelope/{envelopeKey}")]
public IActionResult Get(string envelopeKey)
{
try
{
logger.Info("EnvelopeController/Get");
// Validate Envelope Key and load envelope
envelopeService.EnsureValidEnvelopeKey(envelopeKey);
EnvelopeResponse response = envelopeService.LoadEnvelope(envelopeKey);
return Json(response);
}
catch (Exception e)
{
return ErrorResponse(e);
}
}
[HttpPost]
[Route("api/envelope/{envelopeKey}")]
public async Task<IActionResult> Update(string envelopeKey)
{
try
{
logger.Info("EnvelopeController/Update");
// Validate Envelope Key and load envelope
envelopeService.EnsureValidEnvelopeKey(envelopeKey);
EnvelopeResponse response = envelopeService.LoadEnvelope(envelopeKey);
var Request = ControllerContext.HttpContext.Request;
var document = envelopeService.GetDocument(Request, envelopeKey);
string annotationData = await envelopeService.EnsureValidAnnotationData(Request);
envelopeService.InsertDocumentStatus(new DocumentStatus()
{
EnvelopeId = response.Envelope.Id,
ReceiverId = response.Receiver.Id,
Value = annotationData,
Status = Common.Constants.DocumentStatus.Signed
});
return Ok();
}
catch (Exception e)
{
return ErrorResponse(e);
}
}
}
}