When this method is executed in the Controller:
[Route("deleteIncCloseOut")]
[HttpDelete]
[AuditApi]
public bool deleteIncidentCloseOut(int ID)
{
try
{
using (ESSDataContext ctx = new ESSDataContext())
{
ctx.DeleteIncidentCloseOut(ID);
this.GetCurrentAuditScope().SetCustomField("Dynamic", new { IncidentCloseOutID = ID });
return true;
}
}
catch (Exception ex)
{
log.Error($"{ex.StackTrace}");
return false;
throw ex;
}
}
There is an exception with the stored procedure DeleteIncidentCloseOut(ID)
, and so the CustomField of the AuditEvent is not being set. However, the DataProvider's InsertEvent is still being executed.
My problem is that in my InsertEvent I have to populate two tables. One table has a brief description of the audit event, and the other contains the properties and values of the object that is set as the CustomField of the AuditEvent object. In this case, I create a dynamic object with the ID as the property. So, I get an entry in my first table that the IncidentCloseOut has been deleted (but actually it hasn't, since an exception was thrown), but I do not get the ID of the supposedly deleted event in the second table (since there was no CustomField set). So I am getting false auditing information. Preferably, the stored procedure wouldn't throw an exception, but I would like the auditing to be correct, even if an exception is thrown.
How can I rectify/improve this situation?