-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
98 lines (91 loc) · 3.77 KB
/
Program.cs
File metadata and controls
98 lines (91 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeeManager
{
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public string Department { get; set; }
public decimal Salary { get; set; }
public int YearsAtWork { get; set; }
}
internal class Program
{
public static List<Employee> employeesBySalary(Dictionary<string, List<Employee>> workers, string department)
{
if (workers.ContainsKey(department))
{
return workers[department].Where(b => b.Salary > 2000).ToList();
}
else
{
Console.WriteLine($"There is no {department} in company");
return new List<Employee>();
}
}
public static List<Employee> employeesByYearsAtWork(Dictionary<string, List<Employee>> workers, int years)
{
var allEmployees = workers.Values.SelectMany(w => w).ToList();
return allEmployees.Where(e => e.YearsAtWork > years).ToList();
}
public static void countEmployees(Dictionary<string, List<Employee>> workers)
{
var groupedByParameter = workers.Select(b => new
{
Department = b.Key,
EmployeesCount = b.Value.Count()
}).ToList();
foreach (var employee in groupedByParameter)
{
Console.WriteLine($"{employee.Department}: {employee.EmployeesCount} employees");
}
}
static void Main(string[] args)
{
Dictionary<string, List<Employee>> workers = new Dictionary<string, List<Employee>>
{
{"HR", new List<Employee>
{
new Employee{Id = 10, Name = "George", Salary = 2000, YearsAtWork = 2},
new Employee{Id = 11, Name = "Marta", Salary = 4000, YearsAtWork =3},
new Employee{Id = 12, Name = "Alboniy", Salary = 13000, YearsAtWork = 6}
}
},
{"IT", new List<Employee>
{
new Employee{Id = 13, Name = "Max", Salary = 12000, YearsAtWork = 4},
new Employee{Id = 14, Name = "Mitro", Salary = 24000, YearsAtWork = 9},
new Employee{Id = 15, Name = "Orban", Salary = 513000, YearsAtWork = 20}
}
},
{"Finance", new List<Employee>
{
new Employee{Id = 16, Name = "Nazar", Salary = 1000, YearsAtWork = 1},
new Employee{Id = 17, Name = "Nikita", Salary = 500, YearsAtWork = 0},
new Employee{Id = 18, Name = "Michal", Salary = 17000, YearsAtWork = 6}
}
}
};
var sortedEmployees = employeesBySalary(workers, "Finance");
foreach (var employee in sortedEmployees)
{
Console.WriteLine($"Id: {employee.Id} Name: {employee.Name} Salary: {employee.Salary}" +
$"Years at work: {employee.YearsAtWork}");
}
Console.WriteLine("--------------------");
var employeesByYears = employeesByYearsAtWork(workers, 5);
foreach (var employee in employeesByYears)
{
Console.WriteLine($"Id: {employee.Id} Name: {employee.Name} Salary: {employee.Salary}" +
$"Years at work: {employee.YearsAtWork}");
}
Console.WriteLine("-----------------------");
countEmployees(workers);
Console.ReadLine();
}
}
}