Skip to content

Commit

Permalink
Ignore when entity was not updated
Browse files Browse the repository at this point in the history
  • Loading branch information
saturn72 committed Jul 11, 2023
1 parent 00e2f3d commit 390a472
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
3 changes: 3 additions & 0 deletions EfAudit/AuditSaveChangesInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ private async Task OnSavedChanges(DbContext? context)
if (_record == default)
throw new InvalidOperationException();

if (_record.Entities == default || !_record.Entities.Any())
return;

foreach (var e in _record.Entities.Where(x => x.State == Added))
{
var entry = _trackedEntities[e.Uuid];
Expand Down
1 change: 0 additions & 1 deletion EfAudit/Common/Extensions/HttpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public static class HttpExtensions
{
if (httpContext == default)
return default;

return httpContext.User?.FindFirstValue(ClaimTypes.NameIdentifier);
}
}
Expand Down
2 changes: 1 addition & 1 deletion EfAudit/EfAudit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageId>EfAudit</PackageId>
<PackageVersion>1.0.23</PackageVersion>
<PackageVersion>1.0.24</PackageVersion>
<Authors>roi@saturn72.com</Authors>
<Company>saturn technologies</Company>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
22 changes: 12 additions & 10 deletions Sample/Server/Controllers/AuditTrailController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ public class AuditTrailController : ControllerBase, IAuditRecordHandler
{
private static readonly List<object> _records = new();

/// <summary>
/// Gets all audittrail records
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult GetAllRecords()
{
return Ok(_records);
}

[NonAction]
public async Task Handle(IServiceProvider services, AuditRecord auditRecord, CancellationToken cancellationToken)
{
Expand All @@ -31,5 +21,17 @@ public async Task Handle(IServiceProvider services, AuditRecord auditRecord, Can
if (r != null)
_records.Add(r);
}


/// <summary>
/// Gets all audittrail records
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult GetAllRecords()
{
return Ok(_records);
}

}
}
4 changes: 3 additions & 1 deletion Sample/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
using Server.Handlers;

var builder = WebApplication.CreateBuilder(args);

// options 1:
//add efAudit services.
// this is an example for using multiple audit handlers
builder.Services.AddEfAudit(
builder.Configuration,
RabbitMqEfAuditHandler.Handle // second audit handler
RabbitMqEfAuditHandler.Handle
// second audit handler
);

//register EF DbContext
Expand Down

0 comments on commit 390a472

Please sign in to comment.