Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string ExportSongsAboveDuration(MusicHubDbContext context, int duration)
- {
- var songs = context.Songs
- .Where(d => d.Duration.TotalSeconds > duration)
- .Select(x => new ExportSongDto
- {
- SongName = x.Name,
- Writer = x.Writer.Name,
- Performer = x.SongPerformers.Select(p => p.Performer.FirstName + " " + p.Performer.LastName).FirstOrDefault(),
- AlbumProducer = x.Album.Producer.Name,
- Duration = x.Duration.ToString("c")
- })
- .OrderBy(x => x.SongName)
- .ThenBy(w => w.Writer)
- .ToArray();
- var xmlSerializer = new XmlSerializer(typeof(ExportSongDto[]), new XmlRootAttribute("Songs"));
- var sb = new StringBuilder();
- var namespaces = new XmlSerializerNamespaces(new[]
- {
- XmlQualifiedName.Empty
- });
- xmlSerializer.Serialize(new StringWriter(sb), songs, namespaces);
- return sb.ToString().TrimEnd();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement