58 lines
1.8 KiB
C#
58 lines
1.8 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 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;
|
|
|
|
if (!Enum.TryParse<EnvelopeHistoryActionType>(actionTypeString, out var actionType))
|
|
{
|
|
return BadRequest();
|
|
};
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|