Exemplo n.º 1
0
        public void UpdateSongRating(string songTitle, int songRating, Album album = null)
        {
            using (CDCatalogEntities context = new CDCatalogEntities())
            {
                Song song;
                if (album == null)
                    song = GetSongByID(SearchSongsBySongTitle(songTitle).First().SongID);
                else
                {
                    var songs = SearchSongsBySongTitle(songTitle);
                    song = GetSongByID((songs.Where(s => s.Album == album.Title).FirstOrDefault()).SongID);
                }
                song.Rating = songRating;

                context.Songs.Attach(song);
                var entry = context.Entry(song);
                entry.Property(e => e.Rating).IsModified = true;
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public void UpdateAlbumRating(string albumTitle, int albumRating, string artistName = null)
        {
            using (CDCatalogEntities context = new CDCatalogEntities())
            {
                Album album;
                if (artistName == null)
                {
                    album = GetAlbumByID(SearchAlbumsByAlbumTitle(albumTitle).First().AlbumId);
                }
                else
                {
                    var albums = SearchAlbumsByAlbumTitle(albumTitle).ToList();
                    album = GetAlbumByID(albums.Where(a => a.Artist_Name == artistName).FirstOrDefault().AlbumId);
                }
                album.Rating = albumRating;

                context.Albums.Attach(album);
                var entry = context.Entry(album);
                entry.Property(e => e.Rating).IsModified = true;
                context.SaveChanges();
            }
        }