diff --git a/Oqtane.Server/Repository/Context/DBContextBase.cs b/Oqtane.Server/Repository/Context/DBContextBase.cs index 8fb37ffb..587f078e 100644 --- a/Oqtane.Server/Repository/Context/DBContextBase.cs +++ b/Oqtane.Server/Repository/Context/DBContextBase.cs @@ -70,6 +70,20 @@ namespace Oqtane.Repository item.CurrentValues[nameof(IAuditable.ModifiedBy)] = username; item.CurrentValues[nameof(IAuditable.ModifiedOn)] = date; } + + if (item.Entity is ISoftDeletable softDeleted) + { + if ((bool)item.CurrentValues[nameof(ISoftDeletable.IsSoftDeleted)]) + { + item.CurrentValues[nameof(ISoftDeletable.DeletedBy)] = username; + item.CurrentValues[nameof(ISoftDeletable.DeletedOn)] = date; + } + else + { + item.CurrentValues[nameof(ISoftDeletable.DeletedBy)] = null; + item.CurrentValues[nameof(ISoftDeletable.DeletedOn)] = null; + } + } } return base.SaveChanges(); diff --git a/Oqtane.Shared/Models/ISoftDeletable.cs b/Oqtane.Shared/Models/ISoftDeletable.cs new file mode 100644 index 00000000..a0c1f370 --- /dev/null +++ b/Oqtane.Shared/Models/ISoftDeletable.cs @@ -0,0 +1,11 @@ +using System; + +namespace Oqtane.Models +{ + public interface ISoftDeletable + { + string DeletedBy { get; set; } + DateTime? DeletedOn { get; set; } + bool IsSoftDeleted { get; set; } + } +}