internal static Subject ToDto(Entities.Subject subject, bool include_relations, bool include_invisible_media) { if (subject == null) { return(null); } var subject_type = subject.GetType(); if (subject_type == typeof(Entities.Person)) { return(PersonRepository.ToDto((Entities.Person)subject, include_relations, include_invisible_media)); } else if (subject_type == typeof(Entities.Artist)) { return(ArtistRepository.ToDto((Entities.Artist)subject, include_relations, include_invisible_media)); } else if (subject_type == typeof(Entities.Song)) { return(SongRepository.ToDto((Entities.Song)subject, include_relations, include_invisible_media)); } else { throw new ArgumentException("The subject type was not recognized", nameof(subject)); } }
internal static Playlist ToDto(Entities.Playlist playlist, bool include_relations = false) { if (playlist == null) { return(null); } if (include_relations) { return(new Playlist { Id = playlist.Id, Description = playlist.Description, User = AccountRepository.ToDto(playlist.User), Tracks = playlist.Tracks .OrderBy(t => t.Index) .Select(t => SongRepository.ToDto(t.Song, false, false)) .ToList() }); } else { return(new Playlist { Id = playlist.Id, Description = playlist.Description }); } }
internal static Artist ToDto(Entities.Artist artist, bool include_relations, bool include_invisible_media) { if (artist == null) { return(null); } if (include_relations) { return(new Artist { Id = artist.Id, Name = artist.Name, YearStarted = artist.YearStarted, YearQuit = artist.YearQuit, Text = artist.Text, DateUpdate = artist.DateUpdate ?? artist.DateInsert, PastMembers = artist.Members .Where(ap => !ap.Active) .Select(ap => PersonRepository.ToDto(ap.Person, false, include_invisible_media)) .ToList(), CurrentMembers = artist.Members .Where(ap => ap.Active) .Select(ap => PersonRepository.ToDto(ap.Person, false, include_invisible_media)) .ToList(), Songs = artist.Songs .Select(@as => SongRepository.ToDto(@as.Song, false, include_invisible_media)) .ToList(), Media = artist.Media == null ? null : artist.Media .Where(medium => medium.Type.Visible | include_invisible_media) .Select(medium => MediumRepository.ToDto(medium, true)) .ToList(), Tags = artist.Tags == null ? null : artist.Tags.Select(st => TagRepository.ToDto(st.Tag)).ToList() }); } else { return(new Artist { Id = artist.Id, Name = artist.Name, YearStarted = artist.YearStarted, YearQuit = artist.YearQuit, Text = artist.Text, DateUpdate = artist.DateUpdate ?? artist.DateInsert }); } }