Advertisement
Guest User

Find Latest 10 Projects

a guest
Oct 30th, 2019
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. public static string GetLatestProjects(SoftUniContext context)
  2.         {
  3.             StringBuilder sb = new StringBuilder();
  4.  
  5.             var projects = context
  6.                 .Projects
  7.                 .OrderByDescending(p => p.StartDate)
  8.                 .ThenBy(p => p.Name)
  9.                 .Select(p => new
  10.                 {
  11.                     p.Name,
  12.                     p.Description,
  13.                     p.StartDate
  14.                 })
  15.                 .Take(10)
  16.                 .ToList();
  17.  
  18.             foreach (var p in projects)
  19.             {
  20.                 sb.AppendLine(p.Name);
  21.                 sb.AppendLine(p.Description);
  22.                 sb.AppendLine(p.StartDate.ToString("M/d/yyyy h:mm:ss tt"));
  23.             }
  24.  
  25.             return sb.ToString().TrimEnd();
  26.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement