-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f7f58f
commit e603470
Showing
3 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,36 @@ | ||
namespace N26_HT2.Extention; | ||
|
||
public class CollectionExtensions | ||
public static class CollectionExtensions | ||
{ | ||
|
||
|
||
public static ICollection<Skills> Update(this ICollection<Skills> firstcollection, | ||
ICollection<Skills> secondcollection) | ||
{ | ||
var list = firstcollection.ToList(); | ||
|
||
var addedItems = secondcollection | ||
.ExceptBy(firstcollection.Select(firstItem => firstItem.Id), item => item.Id); | ||
|
||
var removedItems = firstcollection | ||
.ExceptBy(secondcollection.Select(firstItem => firstItem.Id), item => item.Id); | ||
|
||
var intersectKeys = firstcollection.Select(item => item.Id) | ||
.Intersect(secondcollection.Select(item => item.Id)); | ||
|
||
foreach (var item in addedItems) | ||
list.Add(item); | ||
|
||
foreach (var item in removedItems) | ||
list.Remove(item); | ||
|
||
foreach (var key in intersectKeys) | ||
{ | ||
var firstItem = list.First(a => a.Id == key); | ||
var secondItem = secondcollection.First(a => a.Id == key); | ||
|
||
firstItem.Name = secondItem.Name; | ||
firstItem.Level = secondItem.Level; | ||
} | ||
return list; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters