From 06fddf041b6a5a62270c14d715196ea02e6d6805 Mon Sep 17 00:00:00 2001 From: soroshsabz Date: Thu, 9 Nov 2023 12:32:19 +0330 Subject: [PATCH 1/5] Update incompatible packages --- Source/BSN.Commons/BSN.Commons.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/BSN.Commons/BSN.Commons.csproj b/Source/BSN.Commons/BSN.Commons.csproj index 53808dc..3269580 100644 --- a/Source/BSN.Commons/BSN.Commons.csproj +++ b/Source/BSN.Commons/BSN.Commons.csproj @@ -51,11 +51,11 @@ - - + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -63,7 +63,7 @@ - + From 672f6b21bb8525f8005cb896272eaac164872b7e Mon Sep 17 00:00:00 2001 From: soroshsabz Date: Thu, 9 Nov 2023 12:47:22 +0330 Subject: [PATCH 2/5] Add soft deletable interface --- Source/BSN.Commons/ISoftDeletable.cs | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Source/BSN.Commons/ISoftDeletable.cs diff --git a/Source/BSN.Commons/ISoftDeletable.cs b/Source/BSN.Commons/ISoftDeletable.cs new file mode 100644 index 0000000..a5857e4 --- /dev/null +++ b/Source/BSN.Commons/ISoftDeletable.cs @@ -0,0 +1,29 @@ +using System; + +namespace BSN.Commons +{ + /// + /// Provides a mechanism for soft deletion. + /// + /// Soft deletion means that this object is not completely destroyed, but it goes in a deleted state, + /// and you can ask this object if you are deleted or not? + /// + public interface ISoftDeletable + { + /// + /// Shows the time of deletion. + /// + /// + /// If this object is not deleted, this property returns . + /// + DateTime DeletedAt + { + get; + } + + /// + /// Delete this object. + /// + void Delete(); + } +} From 4d4c7ead6dfd0ef5a5751bd7c518ca00a148e185 Mon Sep 17 00:00:00 2001 From: soroshsabz Date: Thu, 9 Nov 2023 13:12:15 +0330 Subject: [PATCH 3/5] Add base class. --- Source/BSN.Commons/SoftDeletableBase.cs | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Source/BSN.Commons/SoftDeletableBase.cs diff --git a/Source/BSN.Commons/SoftDeletableBase.cs b/Source/BSN.Commons/SoftDeletableBase.cs new file mode 100644 index 0000000..4ac8cf3 --- /dev/null +++ b/Source/BSN.Commons/SoftDeletableBase.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BSN.Commons +{ + /// + public abstract class SoftDeletableBase : ISoftDeletable + { + /// + public DateTime DeletedAt + { + get; + private set; + } + + /// + public virtual void Delete() + { + if (DeletedAt != DateTime.MinValue) + { + throw new InvalidOperationException("This object is already deleted."); + } + + DeletedAt = DateTime.UtcNow; + } + } +} From d8b54bee257ef66ead73d439245de9e85cd82790 Mon Sep 17 00:00:00 2001 From: soroshsabz Date: Thu, 9 Nov 2023 13:22:35 +0330 Subject: [PATCH 4/5] Add IsDeleted --- Source/BSN.Commons/ISoftDeletable.cs | 8 ++++++++ Source/BSN.Commons/SoftDeletableBase.cs | 3 +++ 2 files changed, 11 insertions(+) diff --git a/Source/BSN.Commons/ISoftDeletable.cs b/Source/BSN.Commons/ISoftDeletable.cs index a5857e4..4f8b99e 100644 --- a/Source/BSN.Commons/ISoftDeletable.cs +++ b/Source/BSN.Commons/ISoftDeletable.cs @@ -21,6 +21,14 @@ DateTime DeletedAt get; } + /// + /// Shows if this object is deleted or not. + /// + bool IsDeleted + { + get; + } + /// /// Delete this object. /// diff --git a/Source/BSN.Commons/SoftDeletableBase.cs b/Source/BSN.Commons/SoftDeletableBase.cs index 4ac8cf3..4173688 100644 --- a/Source/BSN.Commons/SoftDeletableBase.cs +++ b/Source/BSN.Commons/SoftDeletableBase.cs @@ -14,6 +14,9 @@ public DateTime DeletedAt private set; } + /// + public bool IsDeleted => DeletedAt != DateTime.MinValue; + /// public virtual void Delete() { From 6100b2ea6ca00cc33610a80ef6d6c2ee8769ccdc Mon Sep 17 00:00:00 2001 From: soroshsabz Date: Thu, 9 Nov 2023 13:29:32 +0330 Subject: [PATCH 5/5] Change delete method. --- Source/BSN.Commons/ISoftDeletable.cs | 4 +++- Source/BSN.Commons/SoftDeletableBase.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/BSN.Commons/ISoftDeletable.cs b/Source/BSN.Commons/ISoftDeletable.cs index 4f8b99e..672e158 100644 --- a/Source/BSN.Commons/ISoftDeletable.cs +++ b/Source/BSN.Commons/ISoftDeletable.cs @@ -12,6 +12,8 @@ public interface ISoftDeletable { /// /// Shows the time of deletion. + /// + /// Time based on UTC. /// /// /// If this object is not deleted, this property returns . @@ -32,6 +34,6 @@ bool IsDeleted /// /// Delete this object. /// - void Delete(); + void SoftDelete(); } } diff --git a/Source/BSN.Commons/SoftDeletableBase.cs b/Source/BSN.Commons/SoftDeletableBase.cs index 4173688..23d4c2e 100644 --- a/Source/BSN.Commons/SoftDeletableBase.cs +++ b/Source/BSN.Commons/SoftDeletableBase.cs @@ -18,7 +18,7 @@ public DateTime DeletedAt public bool IsDeleted => DeletedAt != DateTime.MinValue; /// - public virtual void Delete() + public virtual void SoftDelete() { if (DeletedAt != DateTime.MinValue) {