Aliendreamer

export json

Aug 19th, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1.  public static string ExportPrisonersByCells(SoftJailDbContext context, int[] ids)
  2.         {
  3.             var prisoners = context.Prisoners.Where(x => ids.Any(i => i == x.Id))
  4.                 .ToArray()
  5.                 .Select(p => new
  6.                 {
  7.                     Id= p.Id,
  8.                     Name = p.FullName,
  9.                     CellNumber = p.Cell.CellNumber,
  10.  
  11.                     Officers = p.PrisonerOfficers.Select(o =>new ExportOfficerDto
  12.                     {
  13.                         OfficerName=o.Officer.FullName,
  14.                         Department=o.Officer.Department.Name
  15.  
  16.                     }).OrderBy(o=>o.OfficerName)
  17.                     .ToArray(),
  18.                    
  19.                     TotalOfficerSalary=Math.Round(p.PrisonerOfficers.Sum(o=>o.Officer.Salary),2)
  20.  
  21.                 })
  22.                 .OrderBy(p=>p.Name).ThenBy(p=>p.Id)
  23.                 .ToArray();  
  24.  
  25.             string result = JsonConvert.SerializeObject(prisoners, Formatting.Indented);
  26.            
  27.             return result;
  28.         }
Advertisement
Add Comment
Please, Sign In to add comment