mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
AddRange() support for ICollection
This commit is contained in:
parent
51b649b1af
commit
b5ed619476
1 changed files with 16 additions and 5 deletions
|
|
@ -31,7 +31,7 @@ public void SaveSnapshotBatch()
|
|||
|
||||
private void AddNewRules()
|
||||
{
|
||||
preExistingSnapshotRules = dbContext.Rules.Where(rule => rawRules.Contains(rule.Raw)).AsNoTracking();
|
||||
preExistingSnapshotRules = dbContext.Rules.Where(rule => rawRules.Contains(rule.Raw));
|
||||
var newSnapshotRawRules = rawRules.Except(preExistingSnapshotRules.Select(x => x.Raw));
|
||||
newSnapshotRules = newSnapshotRawRules.Select(newSnapshotRawRule => new Rule {Raw = newSnapshotRawRule})
|
||||
.ToList();
|
||||
|
|
@ -40,10 +40,21 @@ private void AddNewRules()
|
|||
|
||||
private void AddSnapshotRules()
|
||||
{
|
||||
snapshot.SnapshotRules = preExistingSnapshotRules
|
||||
.Concat(newSnapshotRules)
|
||||
.Select(rule => new SnapshotRule {Rule = rule, Snapshot = snapshot})
|
||||
.ToList();
|
||||
if (snapshot.SnapshotRules == null)
|
||||
snapshot.SnapshotRules = new List<SnapshotRule>();
|
||||
snapshot.SnapshotRules.AddRange(preExistingSnapshotRules
|
||||
.Concat(newSnapshotRules)
|
||||
.Select(rule => new SnapshotRule {Rule = rule, Snapshot = snapshot})
|
||||
.ToList());
|
||||
}
|
||||
}
|
||||
|
||||
public static class CollectionExtensions
|
||||
{
|
||||
public static void AddRange<T>(this ICollection<T> destination, IEnumerable<T> source)
|
||||
{
|
||||
foreach (var item in source)
|
||||
destination.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue