Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="title"></param>
        /// <param name="artistId"></param>
        /// <param name="albumId"></param>
        /// <param name="trackNumber"></param>
        /// <param name="songRating"></param>
        /// <param name="trackLength"></param>
        /// <param name="genreId"></param>
        /// <returns></returns>
        public static int AddSong(string title, int artistId, int albumId, int trackNumber, int songRating, int trackLength, int genreId)
        {
            var song = new CDCatalogEF.Song();

            try
            {
                song.SongTitle       = title;
                song.ArtistID        = artistId;
                song.AlbumID         = albumId;
                song.SongTrackNumber = trackNumber;
                song.SongRating      = songRating;
                song.SongTrackLength = trackLength;
                song.GenreID         = genreId;

                using (var db = new CDCatalogEntities())
                {
                    db.Songs.Add(song);
                    var resultCount = db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                // Define a new top-level error message.
                string str = "Adding the Song failed. " + ex.Message;

                // Pop-up a messagebox with the message
                MessageBox.Show(str);
            }
            var songId = song.ArtistID; //The song.ArtistID gets updated in the context as its saved

            return(songId);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="title"></param>
        /// <param name="artistId"></param>
        /// <param name="albumId"></param>
        /// <param name="trackNumber"></param>
        /// <param name="songRating"></param>
        /// <param name="trackLength"></param>
        /// <param name="genreId"></param>
        /// <returns></returns>
        public static bool UpdateSong(int songId, string title, int artistId, int albumId, int trackNumber, int songRating, int trackLength, int genreId)
        {
            var song = new CDCatalogEF.Song();

            try
            {
                song.SongTitle       = title;
                song.ArtistID        = artistId;
                song.AlbumID         = albumId;
                song.SongTrackNumber = trackNumber;
                song.SongRating      = songRating;
                song.SongTrackLength = trackLength;
                song.GenreID         = genreId;

                using (var db = new CDCatalogEntities())
                {
                    db.Songs.First(i => i.SongID == songId);
                    int resultCount = db.SaveChanges();
                    return(true); // Executes only if no exception
                }
            }
            catch (Exception ex)
            {
                // Define a new top-level error message.
                string str = "Adding the Song failed. " + ex.Message;

                // Pop-up a messagebox with the message
                MessageBox.Show(str);
            }
            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="songId"></param>
        /// <returns></returns>
        public static bool DeleteSongById(int songId)
        {
            try
            {
                using (var db = new CDCatalogEntities())
                {
                    CDCatalogEF.Song song = db.Songs.Where(n => n.Equals(songId)).Single();
                    db.Songs.Remove(song);
                    return(true);  //if there is an exception, this won't run
                }
            }
            catch (Exception ex)
            {
                // Define a new top-level error message.
                string str = "Deleting the Song failed. " + ex.Message;

                // Pop-up a messagebox with the message
                MessageBox.Show(str);
            }
            return(false);
        }