diff --git a/Mango.Nop.Core/Extensions/CollectionExtensionsNopBaseEntity.cs b/Mango.Nop.Core/Extensions/CollectionExtensionsNopBaseEntity.cs new file mode 100644 index 0000000..3a40306 --- /dev/null +++ b/Mango.Nop.Core/Extensions/CollectionExtensionsNopBaseEntity.cs @@ -0,0 +1,27 @@ +using AyCode.Core.Enums; +using AyCode.Core.Extensions; +using Nop.Core; + +namespace Mango.Nop.Core.Extensions; + +public static class CollectionExtensionsNopBaseEntity +{ + public static void UpdateBaseEntityCollection(this IList source, IList dataItems, bool isRemove) where TDataItem : BaseEntity + { + if (source == null) throw new ArgumentNullException(nameof(source), $"source == null"); + if (dataItems == null) throw new ArgumentNullException(nameof(dataItems), $"dataItems == null"); + + foreach (var dataItem in dataItems) + { + source.UpdateBaseEntityCollection(dataItem, isRemove); + } + } + + public static TrackingState UpdateBaseEntityCollection(this IList source, TDataItem dataItem, bool isRemove) where TDataItem : BaseEntity + { + if (source == null) throw new ArgumentNullException(nameof(source), $"source == null"); + + var index = source.FindIndex(x => x.Id == dataItem.Id); + return source.UpdateCollectionByIndex(index, dataItem, isRemove); + } +} \ No newline at end of file diff --git a/Mango.Nop.Core/Extensions/GenericAttributeExtensions.cs b/Mango.Nop.Core/Extensions/GenericAttributeExtensions.cs index f8e8a59..9106794 100644 --- a/Mango.Nop.Core/Extensions/GenericAttributeExtensions.cs +++ b/Mango.Nop.Core/Extensions/GenericAttributeExtensions.cs @@ -1,8 +1,9 @@ -using System.Diagnostics.CodeAnalysis; +using AyCode.Core.Interfaces; using AyCode.Utils.Extensions; using LinqToDB.Common; using Nop.Core; using Nop.Core.Domain.Common; +using System.Diagnostics.CodeAnalysis; namespace Mango.Nop.Core.Extensions;