ToEntity() static private method

static private ToEntity ( Medium medium, MintPlayerContext mintplayer_context ) : Entities.Medium
medium Medium
mintplayer_context MintPlayerContext
return Entities.Medium
        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);
        }
Beispiel #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);
        }
        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);
        }