internal static TagCategory ToDto(Entities.TagCategory tagCategory, bool include_relations = false) { if (tagCategory == null) { return(null); } if (include_relations) { return(new TagCategory { Id = tagCategory.Id, Color = tagCategory.Color, Description = tagCategory.Description, Tags = tagCategory.Tags == null ? new List <Tag>() : tagCategory.Tags.Where(t => t.Parent == null).Select(t => TagRepository.ToDto(t)).ToList(), TotalTagCount = tagCategory.Tags == null ? 0 : tagCategory.Tags.Count() }); } else { return(new TagCategory { Id = tagCategory.Id, Color = tagCategory.Color, Description = tagCategory.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 }); } }
internal static Person ToDto(Entities.Person person, bool include_relations, bool include_invisible_media) { if (person == null) { return(null); } if (include_relations) { return(new Person { Id = person.Id, FirstName = person.FirstName, LastName = person.LastName, Born = person.Born, Died = person.Died, Text = person.Text, DateUpdate = person.DateUpdate ?? person.DateInsert, Artists = person.Artists .Select(ap => ArtistRepository.ToDto(ap.Artist, false, include_invisible_media)) .ToList(), Media = person.Media == null ? null : person.Media .Where(medium => medium.Type.Visible | include_invisible_media) .Select(medium => MediumRepository.ToDto(medium, true)) .ToList(), Tags = person.Tags == null ? null : person.Tags .Select(st => TagRepository.ToDto(st.Tag)) .ToList() }); } else { return(new Person { Id = person.Id, FirstName = person.FirstName, LastName = person.LastName, Born = person.Born, Died = person.Died, Text = person.Text, DateUpdate = person.DateUpdate ?? person.DateInsert }); } }
internal static Song ToDto(Entities.Song song, bool include_relations, bool include_invisible_media) { if (song == null) { return(null); } if (include_relations) { var lastLyric = song.Lyrics == null ? null : song.Lyrics.OrderBy(l => l.UpdatedAt).LastOrDefault(); return(new Song { Id = song.Id, Title = song.Title, Released = song.Released, Lyrics = new Lyrics { Text = lastLyric?.Text, Timeline = lastLyric?.Timeline }, Text = song.Text, Description = song.Description, YoutubeId = song.YoutubeId, DailymotionId = song.DailymotionId, PlayerInfo = song.PlayerInfo, DateUpdate = song.DateUpdate ?? song.DateInsert, Artists = song.Artists .Where(@as => @as.Credited) .Select(@as => ArtistRepository.ToDto(@as.Artist, false, false)) .ToList(), UncreditedArtists = song.Artists .Where(@as => [email protected]) .Select(@as => ArtistRepository.ToDto(@as.Artist, false, false)) .ToList(), Media = song.Media == null ? null : song.Media .Where(m => m.Type.Visible | include_invisible_media) .Select(medium => MediumRepository.ToDto(medium, true)) .ToList(), Tags = song.Tags == null ? null : song.Tags .Select(st => TagRepository.ToDto(st.Tag)) .ToList() }); } else { var lastLyric = song.Lyrics == null ? null : song.Lyrics.OrderBy(l => l.UpdatedAt).LastOrDefault(); return(new Song { Id = song.Id, Title = song.Title, Released = song.Released, Lyrics = new Lyrics { Text = lastLyric?.Text, Timeline = lastLyric?.Timeline }, Text = song.Text, Description = song.Description, YoutubeId = song.YoutubeId, DailymotionId = song.DailymotionId, PlayerInfo = song.PlayerInfo, DateUpdate = song.DateUpdate ?? song.DateInsert }); } }