private void UpdateSongsList(Playlist obj) { Songs = new ObservableCollection<Song>(_songRepository.GetSongsFromPlaylist(obj.ID)); ObservableCollection<Song> tempSongs = new ObservableCollection<Song>(); foreach(Song song in Songs) { tempSongs.Add(song); song.ParentPlaylist = obj; } obj.Songs = tempSongs; ClearRepository(_songRepository); OnPropertyChanged("Songs"); OnPropertyChanged("SongListTitle"); }
public void SavePlaylist(Playlist playlist) { using (SqlCommand cmd = new SqlCommand("UPDATE [dbo].[Playlists] SET Playlist_Title=@title, Playlist_Image=@image, User_ID=@userid WHERE Playlist_ID = @playlistid", connection)) { cmd.Parameters.AddWithValue("@title", playlist.Title); cmd.Parameters.AddWithValue("@image", playlist.Image); cmd.Parameters.AddWithValue("@userid", playlist.UserID); cmd.Parameters.AddWithValue("@playlistid", playlist.ID); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } using (SqlCommand cmd = new SqlCommand("DELETE FROM [dbo].[Songs_For_Playlist] WHERE Playlist_ID=@playlistid", connection)) { cmd.Parameters.AddWithValue("@playlistid", playlist.ID); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } using (SqlCommand cmd = new SqlCommand("INSERT INTO [dbo].[Songs_For_Playlist] VALUES (@songid, @playlistid)", connection)) { for (int i = 0; i < playlist.Track_Count; i++) { cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@playlistid", playlist.ID); cmd.Parameters.AddWithValue("@songid", playlist.Songs[i].ID); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } } }
public void DeletePlaylist(Playlist playlist) { using (SqlCommand cmd = new SqlCommand("DELETE FROM [dbo].[Playlists] WHERE Playlist_ID=@playlistid", connection)) { cmd.Parameters.AddWithValue("@playlistid", playlist.ID); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } using (SqlCommand cmd = new SqlCommand("DELETE FROM [dbo].[Songs_For_Playlist] WHERE Playlist_ID=@playlistid", connection)) { cmd.Parameters.AddWithValue("@playlistid", playlist.ID); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } }
public void AddNewPlaylist(Playlist playlist, int userid = 0) { int newid = 0; using (SqlCommand cmd = new SqlCommand("INSERT INTO [dbo].[Playlists] OUTPUT INSERTED.Playlist_ID VALUES (@title, @image, @userid)", connection)) { cmd.Parameters.AddWithValue("@title", playlist.Title); cmd.Parameters.AddWithValue("@image", playlist.Image); cmd.Parameters.AddWithValue("@userid", userid); connection.Open(); newid = (int)cmd.ExecuteScalar(); connection.Close(); playlist.ID = newid; } foreach (Song song in playlist.Songs) { using (SqlCommand cmd = new SqlCommand("INSERT INTO [dbo].[Songs_For_Playlist] VALUES (@songid, @playlistid)", connection)) { cmd.Parameters.AddWithValue("@songid", song.ID); cmd.Parameters.AddWithValue("@playlistid", playlist.ID); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } } }
public PlaylistViewModel(Playlist playlist) { Playlist = playlist; }