コード例 #1
0
        public static Song CreateOrFind(MusicLibraryContext dbContext, string path)
        {
            Song song = dbContext.Songs.FirstOrDefault(_song => _song.Path == path);

            if (song == null)
            {
                // if not found, create a new one
                song = new Song()
                {
                    Path = path
                };

                dbContext.Songs.Add(song);
            }
            else
            {
                dbContext.Songs.Attach(song);
            }

            return(song);
        }
コード例 #2
0
        public static Artist CreateOrFind(MusicLibraryContext dbContext, string name)
        {
            Artist artist = dbContext.Artists.FirstOrDefault(_artist => _artist.Name == name);

            if (artist == null)
            {
                // if not found, create a new one
                artist = new Artist()
                {
                    Name = name
                };

                dbContext.Artists.Add(artist);
            }
            else
            {
                dbContext.Artists.Attach(artist);
            }

            return(artist);
        }
コード例 #3
0
ファイル: Album.cs プロジェクト: WesterWest/Laaud-UWP
        public static Album CreateOrFind(MusicLibraryContext dbContext, string name, int artistId)
        {
            Album album = dbContext.Albums.FirstOrDefault(_album => _album.Name == name && _album.ArtistId == artistId);

            if (album == null)
            {
                // if not found, create a new one
                album = new Album()
                {
                    Name     = name,
                    ArtistId = artistId
                };

                dbContext.Albums.Add(album);
            }
            else
            {
                dbContext.Albums.Attach(album);
            }

            return(album);
        }