Advertisement
Iv555

Untitled

Jun 26th, 2022
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. /T10 Departments with More Than 5 Employees
  2.  
  3.         public static string GetDepartmentsWithMoreThan5Employees(SoftUniContext context)
  4.         {
  5.  
  6.             var departmentsWithMoreThan5Employees = context.Departments.Where(x => x.Employees.Count > 5)
  7.            .Select(x => new
  8.            {
  9.                EmployeesCount = x.Employees.Count,
  10.                DepartmentName = x.Name,
  11.                DeptManagerName = x.Manager.FirstName + " " + x.Manager.LastName,
  12.                DepartmentEmployees = x.Employees.Select(e => new
  13.                {
  14.                    EmployeeFirstName = e.FirstName,
  15.                    EmployeeLastName = e.LastName,
  16.                    EmployeeJobTitle = e.JobTitle
  17.                })
  18.              .OrderBy(e => e.EmployeeFirstName).ThenBy(e => e.EmployeeLastName).ToList()
  19.            })
  20.            //.OrderBy(x => x.EmployeesCount).ThenBy(x => x.DepartmentName)
  21.            .ToList();
  22.  
  23.             StringBuilder sb = new StringBuilder();
  24.  
  25.             foreach (var department in departmentsWithMoreThan5Employees)
  26.             {
  27.                 sb.AppendLine($"{department.DepartmentName} - {department.DeptManagerName}");
  28.                 foreach (var employee in department.DepartmentEmployees)
  29.                 {
  30.                     sb.AppendLine($"{employee.EmployeeFirstName} {employee.EmployeeLastName} - {employee.EmployeeJobTitle}");
  31.                 }
  32.             }
  33.             return sb.ToString().TrimEnd();
  34.  
  35.         }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement