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
                });
            }
        }
Exemple #2
0
        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
                });
            }
        }