Improved to skip new Added entities and if softdelete properties are unmodified

This commit is contained in:
Emanuele Filardo 2019-09-20 17:51:13 +02:00
parent 6ade59cc09
commit 182a156bd8

View File

@ -71,14 +71,16 @@ namespace Oqtane.Repository
item.CurrentValues[nameof(IAuditable.ModifiedOn)] = date;
}
if (item.Entity is ISoftDeletable softDeleted)
if (item.Entity is ISoftDeletable softDeleted && item.State != EntityState.Added)
{
if ((bool)item.CurrentValues[nameof(ISoftDeletable.IsSoftDeleted)])
if ((bool)item.CurrentValues[nameof(ISoftDeletable.IsSoftDeleted)]
&& !item.GetDatabaseValues().GetValue<bool>(nameof(ISoftDeletable.IsSoftDeleted)))
{
item.CurrentValues[nameof(ISoftDeletable.DeletedBy)] = username;
item.CurrentValues[nameof(ISoftDeletable.DeletedOn)] = date;
}
else
else if (!(bool)item.CurrentValues[nameof(ISoftDeletable.IsSoftDeleted)]
&& item.GetDatabaseValues().GetValue<bool>(nameof(ISoftDeletable.IsSoftDeleted)))
{
item.CurrentValues[nameof(ISoftDeletable.DeletedBy)] = null;
item.CurrentValues[nameof(ISoftDeletable.DeletedOn)] = null;