diff --git a/framework/src/Volo.Abp.Auditing/Properties/AssemblyInfo.cs b/framework/src/Volo.Abp.Auditing/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..716e8ca3fe --- /dev/null +++ b/framework/src/Volo.Abp.Auditing/Properties/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Volo.Abp.Auditing.Tests")] diff --git a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/EntityChangeInfo.cs b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/EntityChangeInfo.cs index ca59da3683..f0532e3009 100644 --- a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/EntityChangeInfo.cs +++ b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/EntityChangeInfo.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Volo.Abp.Data; using Volo.Abp.MultiTenancy; @@ -30,10 +31,28 @@ namespace Volo.Abp.Auditing public virtual void Merge(EntityChangeInfo changeInfo) { - //TODO: Gracefully merge (add/update) and also for ExtraProperties foreach (var propertyChange in changeInfo.PropertyChanges) { - PropertyChanges.Add(propertyChange); + var existingChange = PropertyChanges.FirstOrDefault(p => p.PropertyName == propertyChange.PropertyName); + if (existingChange == null) + { + PropertyChanges.Add(propertyChange); + } + else + { + existingChange.NewValue = propertyChange.NewValue; + } + } + + foreach (var extraProperty in changeInfo.ExtraProperties) + { + var key = extraProperty.Key; + if (ExtraProperties.ContainsKey(key)) + { + key = InternalUtils.AddCounter(key); + } + + ExtraProperties[key] = extraProperty.Value; } } } diff --git a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/InternalUtils.cs b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/InternalUtils.cs new file mode 100644 index 0000000000..470c34055b --- /dev/null +++ b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/InternalUtils.cs @@ -0,0 +1,24 @@ +using System; + +namespace Volo.Abp.Auditing +{ + internal static class InternalUtils + { + internal static string AddCounter(string str) + { + if (str.Contains("__")) + { + var splitted = str.Split("__"); + if (splitted.Length == 2) + { + if (int.TryParse(splitted[1], out var num)) + { + return splitted[0] + "__" + (++num); + } + } + } + + return str + "__2"; + } + } +} diff --git a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/InternalUtils_Tests.cs b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/InternalUtils_Tests.cs new file mode 100644 index 0000000000..66b7f2054c --- /dev/null +++ b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/InternalUtils_Tests.cs @@ -0,0 +1,16 @@ +using Shouldly; +using Xunit; + +namespace Volo.Abp.Auditing +{ + public static class InternalUtils_Tests + { + [Fact] + public static void AddCounter() + { + InternalUtils.AddCounter("test").ShouldBe("test__2"); + InternalUtils.AddCounter("test__2").ShouldBe("test__3"); + InternalUtils.AddCounter("test__a").ShouldBe("test__a__2"); + } + } +}