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

61 lines
1.9 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 string? ActionType { get; set; }
public string? ActionDescription { 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("EnvelopeController/Get");
// Validate Envelope Key and load envelope
envelopeService.EnsureValidEnvelopeKey(envelopeKey);
EnvelopeResponse response = envelopeService.LoadEnvelope(envelopeKey);
string actionTypeString = action.ActionType;
string actionDescription = action.ActionDescription;
if (!Enum.TryParse<EnvelopeHistoryActionType>(actionTypeString, out var actionType))
{
return BadRequest();
};
envelopeService.InsertHistoryEntry(new EnvelopeHistoryEntry()
{
ActionDescription = actionDescription,
ActionDate = DateTime.Now,
ActionType = actionType,
EnvelopeId = response.Envelope.Id,
UserReference = response.Receiver.Email
});
return Ok();
}
catch (Exception e)
{
return ErrorResponse(e);
}
}
}
}