Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /T10 Departments with More Than 5 Employees
- public static string GetDepartmentsWithMoreThan5Employees(SoftUniContext context)
- {
- var departmentsWithMoreThan5Employees = context.Departments.Where(x => x.Employees.Count > 5)
- .Select(x => new
- {
- EmployeesCount = x.Employees.Count,
- DepartmentName = x.Name,
- DeptManagerName = x.Manager.FirstName + " " + x.Manager.LastName,
- DepartmentEmployees = x.Employees.Select(e => new
- {
- EmployeeFirstName = e.FirstName,
- EmployeeLastName = e.LastName,
- EmployeeJobTitle = e.JobTitle
- })
- .OrderBy(e => e.EmployeeFirstName).ThenBy(e => e.EmployeeLastName).ToList()
- })
- //.OrderBy(x => x.EmployeesCount).ThenBy(x => x.DepartmentName)
- .ToList();
- StringBuilder sb = new StringBuilder();
- foreach (var department in departmentsWithMoreThan5Employees)
- {
- sb.AppendLine($"{department.DepartmentName} - {department.DeptManagerName}");
- foreach (var employee in department.DepartmentEmployees)
- {
- sb.AppendLine($"{employee.EmployeeFirstName} {employee.EmployeeLastName} - {employee.EmployeeJobTitle}");
- }
- }
- return sb.ToString().TrimEnd();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement