Skip to content

Commit

Permalink
Merge pull request #57 from clintirving/make-save-changes-async-audit…
Browse files Browse the repository at this point in the history
…able

Context - Added override for SaveChangesAsync
  • Loading branch information
clintirving authored Sep 25, 2024
2 parents 7dead2d + a19b175 commit 0d81fd8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions EfYou/DatabaseContext/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Threading.Tasks;
using EfYou.Extensions;
using EfYou.Model.Attributes;
using EfYou.Model.Enumerations;
Expand Down Expand Up @@ -59,6 +60,20 @@ public override int SaveChanges()
return result;
}

public override async Task<int> SaveChangesAsync()
{
ChangeTracker.DetectChanges();

var changedEntities = ChangeTracker.Entries().ToList();
var originalStates = changedEntities.Select(x => x.State).ToList();

var result = await base.SaveChangesAsync();

SaveAudit(changedEntities, originalStates);

return result;
}

public void SetState(object entity, EntityState state)
{
Entry(entity).State = state;
Expand Down

0 comments on commit 0d81fd8

Please sign in to comment.