Inheritance: IMediumRepository
        internal static Entities.Person ToEntity(Person person, MintPlayerContext mintplayer_context)
        {
            if (person == null)
            {
                return(null);
            }
            var entity_person = new Entities.Person
            {
                Id        = person.Id,
                FirstName = person.FirstName,
                LastName  = person.LastName,
                Born      = person.Born,
                Died      = person.Died
            };

            #region Media
            entity_person.Media = person.Media.Select(m => {
                var medium     = MediumRepository.ToEntity(m, mintplayer_context);
                medium.Subject = entity_person;
                return(medium);
            }).ToList();
            #endregion
            #region Tags
            if (person.Tags != null)
            {
                entity_person.Tags = person.Tags.Select(t =>
                {
                    var tag = mintplayer_context.Tags.Find(t.Id);
                    return(new Entities.SubjectTag(entity_person, tag));
                }).ToList();
            }
            #endregion
            return(entity_person);
        }
示例#2
0
        /// <summary>Only use this method for creation of a song</summary>
        internal static Entities.Song ToEntity(Song song, Entities.User user, MintPlayerContext mintplayer_context)
        {
            if (song == null)
            {
                return(null);
            }
            var entity_song = new Entities.Song
            {
                Id       = song.Id,
                Title    = song.Title,
                Released = song.Released
            };

            if (song.Artists != null)
            {
                entity_song.Artists = song.Artists.Select(artist =>
                {
                    var entity_artist = mintplayer_context.Artists.Find(artist.Id);
                    return(new Entities.ArtistSong(entity_artist, entity_song));
                }).ToList();
            }
            entity_song.Lyrics = new List <Entities.Lyrics>(new[] {
                new Entities.Lyrics
                {
                    Song     = entity_song,
                    User     = user,
                    Text     = song.Lyrics.Text,
                    Timeline = song.Lyrics.Timeline
                },
            });
            if (song.Media != null)
            {
                entity_song.Media = song.Media.Select(m =>
                {
                    var medium     = MediumRepository.ToEntity(m, mintplayer_context);
                    medium.Subject = entity_song;
                    return(medium);
                }).ToList();
            }
            #region Tags
            if (song.Tags != null)
            {
                entity_song.Tags = song.Tags.Select(t =>
                {
                    var tag = mintplayer_context.Tags.Find(t.Id);
                    return(new Entities.SubjectTag(entity_song, tag));
                }).ToList();
            }
            #endregion
            return(entity_song);
        }
示例#3
0
        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 Entities.Artist ToEntity(Artist artist, MintPlayerContext mintplayer_context)
        {
            if (artist == null)
            {
                return(null);
            }
            var entity_artist = new Entities.Artist
            {
                Id          = artist.Id,
                Name        = artist.Name,
                YearStarted = artist.YearStarted,
                YearQuit    = artist.YearQuit
            };

            #region Members
            var artist_person = artist.CurrentMembers.Select(person => {
                var entity_person = mintplayer_context.People.Find(person.Id);
                return(new Entities.ArtistPerson(entity_artist, entity_person)
                {
                    Active = true
                });
            }).Union(artist.PastMembers.Select(person => {
                var entity_person = mintplayer_context.People.Find(person.Id);
                return(new Entities.ArtistPerson(entity_artist, entity_person)
                {
                    Active = false
                });
            }));
            entity_artist.Members = artist_person.ToList();
            #endregion
            #region Media
            entity_artist.Media = artist.Media.Select(m => {
                var medium     = MediumRepository.ToEntity(m, mintplayer_context);
                medium.Subject = entity_artist;
                return(medium);
            }).ToList();
            #endregion
            #region Tags
            if (artist.Tags != null)
            {
                entity_artist.Tags = artist.Tags.Select(t =>
                {
                    var tag = mintplayer_context.Tags.Find(t.Id);
                    return(new Entities.SubjectTag(entity_artist, tag));
                }).ToList();
            }
            #endregion

            return(entity_artist);
        }
        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
                });
            }
        }
示例#6
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
                });
            }
        }