diff --git a/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IDeletionAuditedObject.cs b/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IDeletionAuditedObject.cs index be59ea0431..a7be0c29a1 100644 --- a/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IDeletionAuditedObject.cs +++ b/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IDeletionAuditedObject.cs @@ -10,7 +10,7 @@ public interface IDeletionAuditedObject : IHasDeletionTime /// /// Id of the deleter user. /// - Guid? DeleterId { get; set; } + Guid? DeleterId { get; } } /// @@ -22,5 +22,5 @@ public interface IDeletionAuditedObject : IDeletionAuditedObject /// /// Reference to the deleter user. /// - TUser Deleter { get; set; } + TUser Deleter { get; } } diff --git a/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IHasDeletionTime.cs b/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IHasDeletionTime.cs index a84fc78c41..ef45b1b057 100644 --- a/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IHasDeletionTime.cs +++ b/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IHasDeletionTime.cs @@ -11,5 +11,5 @@ public interface IHasDeletionTime : ISoftDelete /// /// Deletion time. /// - DateTime? DeletionTime { get; set; } + DateTime? DeletionTime { get; } } diff --git a/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IHasModificationTime.cs b/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IHasModificationTime.cs index b7b7494081..001d07d617 100644 --- a/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IHasModificationTime.cs +++ b/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IHasModificationTime.cs @@ -10,5 +10,5 @@ public interface IHasModificationTime /// /// The last modified time for this entity. /// - DateTime? LastModificationTime { get; set; } + DateTime? LastModificationTime { get; } } diff --git a/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IModificationAuditedObject.cs b/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IModificationAuditedObject.cs index 5ba4fd1e02..48f26b6299 100644 --- a/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IModificationAuditedObject.cs +++ b/framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IModificationAuditedObject.cs @@ -10,7 +10,7 @@ public interface IModificationAuditedObject : IHasModificationTime /// /// Last modifier user for this entity. /// - Guid? LastModifierId { get; set; } + Guid? LastModifierId { get; } } /// @@ -22,5 +22,5 @@ public interface IModificationAuditedObject : IModificationAuditedObject /// /// Reference to the last modifier user of this entity. /// - TUser LastModifier { get; set; } + TUser LastModifier { get; } } diff --git a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditPropertySetter.cs b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditPropertySetter.cs index d85bad82eb..16632420d7 100644 --- a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditPropertySetter.cs +++ b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditPropertySetter.cs @@ -99,7 +99,7 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency { if (targetObject is IHasModificationTime objectWithModificationTime) { - objectWithModificationTime.LastModificationTime = Clock.Now; + ObjectHelper.TrySetProperty(objectWithModificationTime, x => x.LastModificationTime, () => Clock.Now); } } @@ -112,7 +112,7 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency if (!CurrentUser.Id.HasValue) { - modificationAuditedObject.LastModifierId = null; + ObjectHelper.TrySetProperty(modificationAuditedObject, x => x.LastModifierId, () => null); return; } @@ -120,7 +120,7 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency { if (multiTenantEntity.TenantId != CurrentUser.TenantId) { - modificationAuditedObject.LastModifierId = null; + ObjectHelper.TrySetProperty(modificationAuditedObject, x => x.LastModifierId, () => null); return; } } @@ -134,7 +134,7 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency } */ - modificationAuditedObject.LastModifierId = CurrentUser.Id; + ObjectHelper.TrySetProperty(modificationAuditedObject, x => x.LastModifierId, () => CurrentUser.Id); } protected virtual void SetDeletionTime(object targetObject) @@ -143,7 +143,7 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency { if (objectWithDeletionTime.DeletionTime == null) { - objectWithDeletionTime.DeletionTime = Clock.Now; + ObjectHelper.TrySetProperty(objectWithDeletionTime, x => x.DeletionTime, () => Clock.Now); } } } @@ -162,7 +162,7 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency if (!CurrentUser.Id.HasValue) { - deletionAuditedObject.DeleterId = null; + ObjectHelper.TrySetProperty(deletionAuditedObject, x => x.DeleterId, () => null); return; } @@ -170,11 +170,11 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency { if (multiTenantEntity.TenantId != CurrentUser.TenantId) { - deletionAuditedObject.DeleterId = null; + ObjectHelper.TrySetProperty(deletionAuditedObject, x => x.DeleterId, () => null); return; } } - deletionAuditedObject.DeleterId = CurrentUser.Id; + ObjectHelper.TrySetProperty(deletionAuditedObject, x => x.DeleterId, () => CurrentUser.Id); } } diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/ISoftDelete.cs b/framework/src/Volo.Abp.Core/Volo/Abp/ISoftDelete.cs index 1d7ba66d81..704dd3ba11 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/ISoftDelete.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/ISoftDelete.cs @@ -9,7 +9,7 @@ public interface ISoftDelete { /// - /// Used to mark an Entity as 'Deleted'. + /// Used to mark an Entity as 'Deleted'. /// - bool IsDeleted { get; set; } + bool IsDeleted { get; } } diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs index 1f55bce770..3a8a24bf62 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs @@ -485,7 +485,7 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, } entry.Reload(); - entry.Entity.As().IsDeleted = true; + ObjectHelper.TrySetProperty(entry.Entity.As(), x => x.IsDeleted, () => true); SetDeletionAuditProperties(entry); } diff --git a/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs b/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs index 4180121a9f..2bcfc1bad7 100644 --- a/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs +++ b/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs @@ -253,7 +253,7 @@ public class MemoryDbRepository : RepositoryBase x.IsDeleted, () => true); (await GetCollectionAsync()).Update(entity); } else diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index 0485dd74bc..25f6ce2f3f 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -294,7 +294,7 @@ public class MongoDbRepository if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)) && !IsHardDeleted(entity)) { - ((ISoftDelete)entity).IsDeleted = true; + ObjectHelper.TrySetProperty(((ISoftDelete)entity), x => x.IsDeleted, () => true); ApplyAbpConceptsForDeletedEntity(entity); ReplaceOneResult result; @@ -365,8 +365,7 @@ public class MongoDbRepository { if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)) && !IsHardDeleted(entity)) { - ((ISoftDelete)entity).IsDeleted = true; - + ObjectHelper.TrySetProperty(((ISoftDelete)entity), x => x.IsDeleted, () => true); softDeletedEntities.Add(entity, SetNewConcurrencyStamp(entity)); } else