Exemplo n.º 1
0
        public void AddSong(Song song, string artist, string album)
        {
            using (var session = sessionFactory.OpenSession())
              {
            using (var transaction = session.BeginTransaction())
            {
              Artist matching_artist = session.Query<Artist>().Where(x => x.Name == artist).FirstOrDefault();

              if (matching_artist == null)
              {
            matching_artist = new Artist
            {
              Name = artist
            };
              }

              Album matching_album = matching_artist.Albums.Where(x => x.Name == album).FirstOrDefault();
              if (matching_album == null)
              {
            matching_album = new Album
            {
              Name = album,
              Artist = matching_artist,
              Year = 1000
            };
            matching_artist.AddAlbum(matching_album);
              }
              matching_album.AddSong(song);
              session.Save(matching_artist);
              session.Save(matching_album);
              session.Save(song);
              transaction.Commit();
            }
              }
        }
Exemplo n.º 2
0
 public virtual void AddAlbum(Album album)
 {
     album.Artist = this;
       Albums.Add(album);
 }