Advertisement
Guest User

Employees and Projects

a guest
Oct 30th, 2019
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. public static string GetEmployeesInPeriod(SoftUniContext context)
  2.         {
  3.             StringBuilder sb = new StringBuilder();
  4.  
  5.             var employeesProjects = context.Employees
  6.                     .Where(e => e.EmployeesProjects
  7.                         .Any(ep => ep.Project.StartDate.Year >= 2001 && ep.Project.StartDate.Year <= 2003))
  8.                     .Take(10)
  9.                     .Select(e => new
  10.                     {
  11.                         e.FirstName,
  12.                         e.LastName,
  13.                         ManagerFirstName = e.Manager.FirstName,
  14.                         ManagerLastName = e.Manager.LastName,
  15.                         Projects = e.EmployeesProjects
  16.                             .Select(ep => ep.Project)
  17.                     })
  18.                     .ToList();
  19.  
  20.             foreach (var ep in employeesProjects)
  21.             {
  22.                 sb.AppendLine($"{ep.FirstName} {ep.LastName} – Manager: {ep.ManagerFirstName} {ep.ManagerLastName}");
  23.  
  24.                 foreach (var project in ep.Projects)
  25.                 {
  26.                     if (project.EndDate == null)
  27.                     {
  28.                         sb.AppendLine($"--{project.Name} - {project.StartDate.ToString("M/d/yyyy h:mm:ss tt")} - not finished");
  29.                     }
  30.                     else
  31.                     {
  32.                         sb.AppendLine($"--{project.Name} - {project.StartDate.ToString("M/d/yyyy h:mm:ss tt")} - {((DateTime)(project.EndDate)).ToString("M/d/yyyy h:mm:ss tt")}");//project.EndDate.Value.ToString("M/d/yyyy h:mm:ss tt") also works locally, but not in Judge!
  33.                     }
  34.                 }
  35.             }
  36.  
  37.             return sb.ToString().TrimEnd();
  38.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement