27 lines
1.1 KiB
C#
27 lines
1.1 KiB
C#
using AyCode.Core.Enums;
|
|
using AyCode.Core.Extensions;
|
|
using Nop.Core;
|
|
|
|
namespace Mango.Nop.Core.Extensions;
|
|
|
|
public static class CollectionExtensionsNopBaseEntity
|
|
{
|
|
public static void UpdateBaseEntityCollection<TDataItem>(this IList<TDataItem> source, IList<TDataItem> 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<TDataItem>(this IList<TDataItem> 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);
|
|
}
|
|
} |