Merge pull request #87 from fileman/SoftDeletable
Add basic support for SoftDeletable
This commit is contained in:
@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Identity;
|
|||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
|
using Oqtane.Shared;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@ -70,6 +71,22 @@ namespace Oqtane.Repository
|
|||||||
item.CurrentValues[nameof(IAuditable.ModifiedBy)] = username;
|
item.CurrentValues[nameof(IAuditable.ModifiedBy)] = username;
|
||||||
item.CurrentValues[nameof(IAuditable.ModifiedOn)] = date;
|
item.CurrentValues[nameof(IAuditable.ModifiedOn)] = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (item.Entity is IDeletable deleted && item.State != EntityState.Added)
|
||||||
|
{
|
||||||
|
if ((bool)item.CurrentValues[nameof(IDeletable.IsDeleted)]
|
||||||
|
&& !item.GetDatabaseValues().GetValue<bool>(nameof(IDeletable.IsDeleted)))
|
||||||
|
{
|
||||||
|
item.CurrentValues[nameof(IDeletable.DeletedBy)] = username;
|
||||||
|
item.CurrentValues[nameof(IDeletable.DeletedOn)] = date;
|
||||||
|
}
|
||||||
|
else if (!(bool)item.CurrentValues[nameof(IDeletable.IsDeleted)]
|
||||||
|
&& item.GetDatabaseValues().GetValue<bool>(nameof(IDeletable.IsDeleted)))
|
||||||
|
{
|
||||||
|
item.CurrentValues[nameof(IDeletable.DeletedBy)] = null;
|
||||||
|
item.CurrentValues[nameof(IDeletable.DeletedOn)] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.SaveChanges();
|
return base.SaveChanges();
|
||||||
|
11
Oqtane.Shared/Shared/IDeletable.cs
Normal file
11
Oqtane.Shared/Shared/IDeletable.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Oqtane.Shared
|
||||||
|
{
|
||||||
|
public interface IDeletable
|
||||||
|
{
|
||||||
|
string DeletedBy { get; set; }
|
||||||
|
DateTime? DeletedOn { get; set; }
|
||||||
|
bool IsDeleted { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user