Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string ExportPrisonersInbox(SoftJailDbContext context, string prisonersNames)
- {
- var names = prisonersNames.Split(',', StringSplitOptions.RemoveEmptyEntries).ToArray();
- var prisoners = context.Prisoners
- .Where(x=>names.Any(i=>i==x.FullName))
- .ToArray()
- .Select(x=>new ExportPrisonerDto
- {
- Id = x.Id,
- Name = x.FullName,
- IncarcerationDate = x.IncarcerationDate.ToString("yyyy-MM-dd",CultureInfo.InvariantCulture),
- EncruptedMessages = x.Mails.Select(m=>new ExportMessageDto
- {
- Description =new string(m.Description.Reverse().ToArray())
- }).ToArray()
- })
- .OrderBy(x=>x.Name)
- .ThenBy(x=>x.Id)
- .ToArray();
- StringBuilder sb = new StringBuilder();
- var xmlNamespaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });
- var serializer = new XmlSerializer(typeof(ExportPrisonerDto[]), new XmlRootAttribute("Prisoners"));
- serializer.Serialize(new StringWriter(sb),prisoners, xmlNamespaces);
- return sb.ToString();
- }
- // ето как излиза :Д
- <Prisoners>
- <Prisoner>
- <Id>3</Id>
- <Name>Binni Cornhill</Name>
- <IncarcerationDate>1967-04-29</IncarcerationDate>
- <EncruptedMessages>
- <Message>
- <Description>!?sdnasuoht evif-ytnewt rof deksa uoy ro orez artxe na ereht sI</Description>
- </Message>
- </EncruptedMessages>
- </Prisoner>
- ......
Advertisement
Add Comment
Please, Sign In to add comment