Advertisement
social1986

Untitled

Aug 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. var names = prisonersNames.Split(',');
  2.  
  3.             var prisoners = context.Prisoners
  4.                 .Where(p => names.Any(a => a == p.FullName))
  5.                 .Select(p => new PrisonerDto
  6.                 {
  7.                     Id = p.Id,
  8.                     Name = p.FullName,
  9.                     IncarcerationDate = p.IncarcerationDate.ToString("yyyy-MM-dd"),
  10.                     EncryptedMessages = p.Mails.Select(m => new EncryptedMessageDto
  11.                     {
  12.                         Description = Reverse(m.Description)
  13.                     }).ToArray()
  14.                 })
  15.                 .OrderBy(p => p.Name)
  16.                 .ThenBy(p => p.Id)
  17.                 .ToArray();
  18.  
  19.             var serializer = new XmlSerializer(typeof(PrisonerDto[]), new XmlRootAttribute("Prisoners"));
  20.  
  21.             XmlSerializerNamespaces xmlNamespaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });
  22.  
  23.             StringBuilder sb = new StringBuilder();
  24.  
  25.             serializer.Serialize(new StringWriter(sb), prisoners, xmlNamespaces);
  26.  
  27.             return sb.ToString();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement