Jonathan Jenne 56688d2690 20-11-23
2023-11-20 16:42:11 +01:00

52 lines
1.6 KiB
C#

using EnvelopeGenerator.Common;
using EnvelopeGenerator.Web.Services;
using Microsoft.AspNetCore.Mvc;
using static EnvelopeGenerator.Common.Constants;
namespace EnvelopeGenerator.Web.Controllers
{
public class ActionObject
{
public int ActionType { get; set; }
}
public class HistoryController : BaseController
{
private readonly EnvelopeService envelopeService;
public HistoryController(DatabaseService database, LoggingService logging, EnvelopeService envelope) : base(database, logging)
{
envelopeService = envelope;
}
[HttpPost]
[Route("api/history/{envelopeKey}")]
public IActionResult Get(string envelopeKey, [FromBody] ActionObject action)
{
try
{
logger.Info("HistoryController/Post");
// Validate Envelope Key and load envelope
envelopeService.EnsureValidEnvelopeKey(envelopeKey);
EnvelopeResponse response = envelopeService.LoadEnvelope(envelopeKey);
EnvelopeHistoryActionType actionType = (EnvelopeHistoryActionType)action.ActionType;
envelopeService.InsertHistoryEntry(new EnvelopeHistoryEntry()
{
ActionDate = DateTime.Now,
ActionType = actionType,
EnvelopeId = response.Envelope.Id,
UserReference = response.Receiver.Email
});
return Ok();
}
catch (Exception e)
{
return ErrorResponse(e);
}
}
}
}