Skip to content

Commit

Permalink
uy ishi N26 buldi
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdurahmon0412 committed Aug 18, 2023
1 parent 7f7f58f commit e603470
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
34 changes: 32 additions & 2 deletions N26_HT2/Extention/CollectionExtensions.cs
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;
}
}
39 changes: 39 additions & 0 deletions N26_HT2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,42 @@
//- added - qo'shilganlar ( second da bor, first da yo'q ) -bularni first ga qo'shish kerak
//- removed - o'chirilganlar ( second da yo'q, first da bor ) -bularni first dan o'chirish kerak
//- updated - o'zgartirilgan ( first da va second da bor va o'zgartirilgan ) -bularni first da update qilish kerak ( id dan tashqari )

using System.Text.Json;
using N26_HT2;
using N26_HT2.Enums;
using N26_HT2.Extention;


var skillsA = new List<Skills>
{
new("Vue", SkillLevels.Beginner),
new("Angular", SkillLevels.Experienced),
new("React", SkillLevels.Master),
new(".NET", SkillLevels.Expert),
new("Python", SkillLevels.Beginner),
};

Console.WriteLine(JsonSerializer.Serialize(skillsA));
Console.WriteLine();

var updatedItemA = skillsA[2];
updatedItemA.Name = "Node.js";
var updatedItemB = skillsA[2];
updatedItemB.Level = SkillLevels.Beginner;

var skillB = new List<Skills>
{
new("Ruby", SkillLevels.Experienced),
new("Swift", SkillLevels.Expert),
updatedItemA,
updatedItemB,
skillsA[0],
skillsA[3],
};

Console.WriteLine(JsonSerializer.Serialize(skillB));
Console.WriteLine();

var result = skillsA.Update(skillB);
Console.WriteLine(JsonSerializer.Serialize(result));
6 changes: 3 additions & 3 deletions N26_HT2/Skills.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace N26_HT2
public class Skills
{
//- Skill modelidan foydalaning(id, name, level )
public int Id { get; set; }
public Guid Id { get; set; }
public string Name { get; set; }
public SkillLevels Level { get; set; }

public Skills(int id,string name, SkillLevels lavel)
public Skills(string name, SkillLevels lavel)
{
Id = id;
Id = Guid.NewGuid();
Name = name;
Level = lavel;
}
Expand Down

0 comments on commit e603470

Please sign in to comment.