Skip to content

Commit

Permalink
Fix bug in stats listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackburn29 committed Aug 29, 2023
1 parent 037d1db commit 61373ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ private void ExecuteListeners(DbContext context)
{
context.ChangeTracker.DetectChanges();

var changedEntities = context.ChangeTracker.Entries().ToArray();
var changedEntities = context.ChangeTracker.Entries()
.Where(e => e.State is EntityState.Added or EntityState.Modified or EntityState.Deleted)
.ToArray();

foreach (var entry in changedEntities)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ public class CharacterStatsChangeListener : AbstractEntityChangeListener<Fragmen
{
protected override Task OnEntityChanged(FragmentContext context, EntityEntry entry)
{

if (entry.Entity is not CharacterStats statsEntry)
{
return Task.CompletedTask;
}

// Only update the history tables when stats are modified or added for the first time
if (entry.State != EntityState.Modified || entry.State != EntityState.Added)
// If the player stats are deleted (which should never happen), we can ignore stats updates
if (entry.State == EntityState.Deleted)
{
return Task.CompletedTask;
}
Expand Down

0 comments on commit 61373ad

Please sign in to comment.