Add history inserts, add controllers
This commit is contained in:
98
EnvelopeGenerator.Web/Controllers/EnvelopeController.cs
Normal file
98
EnvelopeGenerator.Web/Controllers/EnvelopeController.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using EnvelopeGenerator.Common;
|
||||
using EnvelopeGenerator.Web.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NLog;
|
||||
using static EnvelopeGenerator.Web.Handler.FileHandler;
|
||||
|
||||
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}")]
|
||||
[IgnoreAntiforgeryToken]
|
||||
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}")]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public async Task<IActionResult> Update(string envelopeKey)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("Handling envelope saving.");
|
||||
|
||||
api.EnsureValidEnvelopeKey(envelopeKey);
|
||||
|
||||
EnvelopeResponse r = database.LoadEnvelope(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");
|
||||
}
|
||||
|
||||
State state = api.GetState(logging.LogConfig, database.MSSQL);
|
||||
DocumentStatusModel model = new(state);
|
||||
|
||||
model.InsertOrUpdate(new DocumentStatus()
|
||||
{
|
||||
EnvelopeId = r.Envelope.Id,
|
||||
ReceiverId = r.ReceiverId,
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user