Advertisement
Galina841130

GetDepartmentsWithMoreThan5Employees

Jun 26th, 2022
899
127 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None
  1. public static string GetDepartmentsWithMoreThan5Employees(SoftUniContext context)
  2.         {
  3.             var neededDepartments = context.Departments
  4.                 .Where(x => x.Employees.Count > 5)
  5.                 .OrderBy(x => x.Employees.Count)
  6.                 .ThenBy(x => x.Name)
  7.                 .Select(y => new
  8.                 {
  9.                     departmentName = y.Name,
  10.                     managerFirstName = y.Manager.FirstName,
  11.                     managerLastName = y.Manager.LastName,
  12.                     employees = y.Employees
  13.                 .Select(z => new
  14.                 {
  15.                     employeeFirstName = z.FirstName,
  16.                     employeeLastName = z.LastName,
  17.                     employeeJobTitle = z.JobTitle,
  18.                 })
  19.                     .OrderBy(z => z.employeeFirstName)
  20.                     .ThenBy(z => z.employeeLastName)
  21.                     .ToList()
  22.                 })
  23.                 .ToList();
  24.  
  25.  
  26.             StringBuilder sb = new StringBuilder();
  27.             foreach (var department in neededDepartments)
  28.             {
  29.                 sb.AppendLine($"{department.departmentName} - {department.managerFirstName}  {department.managerLastName}");
  30.                 foreach (var employee in department.employees)
  31.                 {
  32.                     sb.AppendLine($"{employee.employeeFirstName} {employee.employeeLastName} - {employee.employeeJobTitle}");
  33.                 }
  34.             }
  35.             return sb.ToString().TrimEnd();
  36.         }
Advertisement
RAW Paste Data Copied
Advertisement