From 6529acb713aec0c9aa681d1d446d12bbdf222f56 Mon Sep 17 00:00:00 2001 From: Nikoo Asadnejad Date: Sun, 3 Mar 2024 21:39:46 +0330 Subject: [PATCH 1/2] refactor : remove extra id from entities --- .../Domain/Entities/ChangeHistoryEntity.cs | 12 +++++++----- GenericRepository/Domain/Entities/OutBoxMessage.cs | 4 +--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/GenericRepository/Domain/Entities/ChangeHistoryEntity.cs b/GenericRepository/Domain/Entities/ChangeHistoryEntity.cs index dfe7332..a16df60 100644 --- a/GenericRepository/Domain/Entities/ChangeHistoryEntity.cs +++ b/GenericRepository/Domain/Entities/ChangeHistoryEntity.cs @@ -2,9 +2,11 @@ namespace GenericRepository.Domain.Entities; public class ChangeHistoryEntity : BaseEntity { - public long Id { get; set; } - public string OldValue { get; set; } - public string NewValue { get; set; } - public string RelatedEntityId { get; set; } - public string RelatedEntityType { get; set; } + + public string OldValue { get; private set; } + + public string NewValue { get;private set; } + + public string RelatedEntityId { get; private set; } + public string RelatedEntityType { get; private set; } } \ No newline at end of file diff --git a/GenericRepository/Domain/Entities/OutBoxMessage.cs b/GenericRepository/Domain/Entities/OutBoxMessage.cs index 01bb0e9..ae68d43 100644 --- a/GenericRepository/Domain/Entities/OutBoxMessage.cs +++ b/GenericRepository/Domain/Entities/OutBoxMessage.cs @@ -9,14 +9,12 @@ public OutBoxMessage(string type , string content) Type = type; Content = content; } - public OutBoxMessage(IDomainEvent domainEvent) { Type = domainEvent.GetType().Name; Content = JsonSerializer.Serialize(domainEvent); } - - public long Id { get; private set; } + public string Type { get; private set; } public string Content { get; private set; } } \ No newline at end of file From dc89b2d70f09714087814b4ec5fc6c22a56a217f Mon Sep 17 00:00:00 2001 From: Nikoo Asadnejad Date: Sun, 3 Mar 2024 21:45:17 +0330 Subject: [PATCH 2/2] feat(changeLogHistory): add logHistory --- .../Domain/Entities/ChangeHistoryEntity.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/GenericRepository/Domain/Entities/ChangeHistoryEntity.cs b/GenericRepository/Domain/Entities/ChangeHistoryEntity.cs index a16df60..cacd817 100644 --- a/GenericRepository/Domain/Entities/ChangeHistoryEntity.cs +++ b/GenericRepository/Domain/Entities/ChangeHistoryEntity.cs @@ -1,12 +1,23 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + namespace GenericRepository.Domain.Entities; public class ChangeHistoryEntity : BaseEntity { - public string OldValue { get; private set; } public string NewValue { get;private set; } public string RelatedEntityId { get; private set; } + public string RelatedEntityType { get; private set; } + + public void LogHistory(BaseEntity oldEntity , BaseEntity newEntity) + { + OldValue = JsonSerializer.Serialize(oldEntity); + NewValue = JsonSerializer.Serialize(oldEntity); + RelatedEntityId = oldEntity.Id.ToString(); + RelatedEntityType = oldEntity.GetType().Name; + } } \ No newline at end of file