Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string ExportCoachesWithTheirFootballers(FootballersContext context)
- {
- XmlRootAttribute xmlRoot = new XmlRootAttribute("Coaches");
- XmlSerializer xmlSerializer = new XmlSerializer(typeof(ExportCoachDto[]), xmlRoot);
- XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
- namespaces.Add(string.Empty, string.Empty);
- StringBuilder sb = new StringBuilder();
- using StringWriter writer = new StringWriter(sb);
- var coaches = context
- .Coaches
- .Where(c => c.Footballers.Any())
- .Select(c => new ExportCoachDto()
- {
- CoachName = c.Name,
- FootballersCount = c.Footballers.Count(),
- Footballers = c.Footballers
- .Select(f => new ExportCoachFootballerDto()
- {
- Name = f.Name,
- Position = f.PositionType.ToString()
- })
- .OrderBy(f => f.Name)
- .ToArray()
- })
- .OrderByDescending(c => c.FootballersCount)
- .ThenBy(f => f.CoachName)
- .ToArray();
- xmlSerializer.Serialize(writer, coaches, namespaces);
- return sb.ToString().TrimEnd();
- }
Advertisement
Add Comment
Please, Sign In to add comment