Aliendreamer

problem7 ef databasefirst

Jul 3rd, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1.            // 07
  2.             string ifNull = "not finished";
  3.             string formatTime = "M/d/yyyy h:mm:ss tt";
  4.             var employees = softuni.Employees.Where(e => e.EmployeeProjects.Any(p =>
  5.                     p.Project.StartDate.Year >= 2001 && p.Project.StartDate.Year <= 2003))
  6.                 .Take(30)
  7.                 .Select(e => new
  8.                 {
  9.                     name = $"{e.FirstName} {e.LastName}",
  10.                     managerName = $"{e.Manager.FirstName} {e.Manager.LastName}",
  11.                     projects = e.EmployeeProjects.Select(ep => new
  12.                     {
  13.                         ep.Project.Name,
  14.                         ep.Project.StartDate,
  15.                         ep.Project.EndDate
  16.                     })
  17.                 })
  18.                 .ToArray();
  19.  
  20.             foreach (var em in employees)
  21.             {
  22.  
  23.                 Console.WriteLine($"{em.name} - Manager: {em.managerName}");
  24.                 foreach (var p in em.projects)
  25.                 {
  26.  
  27.                     string endTime = p.EndDate.HasValue ? p.EndDate.Value.ToString(formatTime) : ifNull;
  28.                     Console.WriteLine($"--{p.Name} - {p.StartDate.ToString(formatTime)} - {endTime}");
  29.                 }
  30.             }
Advertisement
Add Comment
Please, Sign In to add comment