Page 1 of 1

AuditTrail for ExecuteDelete

Posted: Mon Jan 30, 2023 2:28 pm
by emlim896

Hello,

I used ASP.NET Maker 2022. Audit Trail was not created when using method

int affected = ExecuteDelete("Books", new { Id = 1 });

But it's working in RowDeleted().
Any help would be appreciated.

Thanks


Re: AuditTrail for ExecuteDelete

Posted: Mon Jan 30, 2023 4:19 pm
by MichaelG

If you have enabled audit trail for the table, just use the table's Delete method directly. For example:

int affected = Resolve("Books").Delete(data);


Re: AuditTrail for ExecuteDelete

Posted: Mon Jan 30, 2023 5:12 pm
by emlim896

I'm calling ExecuteDelete() inside RouteAction which triggered by api using jquery.get.

The record was deleted but Audit Trail was not created.


Re: AuditTrail for ExecuteDelete

Posted: Tue Jan 31, 2023 6:09 am
by MichaelG

Did you try?

If you have enabled audit trail for the table, just use the table's Delete method directly. For example:
int affected = Resolve("Books").Delete(data);


Re: AuditTrail for ExecuteDelete

Posted: Tue Jan 31, 2023 12:27 pm
by emlim896

what (data) should I put?
I tried
int affected = Resolve("Books").Delete( { Id = 1 } );
It doesn't work, affected always return 0 and record was not deleted.


Re: AuditTrail for ExecuteDelete

Posted: Tue Jan 31, 2023 2:57 pm
by MichaelG

Make sure that the field name/value is correct. Also enable debug mode (Tools -> Advanced Settings -> Debug) to check for any errors.


Re: AuditTrail for ExecuteDelete

Posted: Tue Jan 31, 2023 3:22 pm
by emlim896

my script:

  app.MapGet("/api/delQueue/{guid}", (string guid) => {
    int affected = ExecuteDelete("Queue", new {Guid = guid} );  // working, affected=1, record deleted
    //int affected = Resolve("Queue").Delete( new {Guid = guid} ); // failed, affected=0, record not delete
    return affected;
  });

with debug mode, all SQL scripts were shown but not the script in app.MapGet.


Re: AuditTrail for ExecuteDelete

Posted: Wed Feb 01, 2023 6:11 am
by MichaelG

To see why the codes are not working, open your project with Visual Studio, add a break point to the Delete method of the "Queue" table (located in "Models/Queue.cs"), step through the codes and debug from there.


Re: AuditTrail for ExecuteDelete

Posted: Wed Feb 01, 2023 4:49 pm
by emlim896

Thanks, problem solved.

new script:

app.MapGet("/api/delQueue/{guid}", (string guid) => {
  var row = ExecuteRow("select id from Queue where Guid='"+guid+"'");
  int res = Resolve("Queue").Delete(row);
  return res;
});