private void button2_Click(object sender, EventArgs e) { if (selectedPlaylist != null) { int rowIndex = DGVPlaylist.CurrentCell.RowIndex; if (rowIndex < 0) { return; } if (DGVPlaylist.Rows[rowIndex].Tag is Playlist playlist) { if (MessageBox.Show($"Are you sure want to delete this playlist {playlist.Name}?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DGVPlaylist.Rows.RemoveAt(rowIndex); if (playlist.PlaylistTracks != null) { foreach (var playlistTrack in playlist.PlaylistTracks) { Db.Remove(playlistTrack); } } Db.Playlists?.Remove(playlist); Db.SaveChanges(); txtPlaylistName.Clear(); MessageBox.Show($"{playlist.Name} was deleted successfully!", "Info:", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
private void btnAddTracks_Click(object sender, EventArgs e) { if (selectedPlaylist != null) { var newPlaylistTrack = new PlaylistTrack() { PlaylistId = selectedPlaylist.PlaylistId, TrackId = comboBoxTracklist.SelectedIndex + 1 }; var checkingExistingTracks = db.PlaylistTracks.Where(pt => pt.PlaylistId == selectedPlaylist.PlaylistId && pt.TrackId == comboBoxTracklist.SelectedIndex + 1); if (checkingExistingTracks.ToArray().Length > 0) { MessageBox.Show("Track already exists!", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } db.PlaylistTracks.Add(newPlaylistTrack); comboBoxTracklist.SelectedIndex = 0; db.SaveChanges(); LoadPlaylistTracks(); } }
private void btnAdd_Click(object sender, EventArgs e) { if (selectedPlaylist != null) { trackList = db.Tracks.ToList(); var newPlaylistTrack = new PlaylistTrack() { PlaylistId = selectedPlaylist.PlaylistId, TrackId = checkedListBoxTracks.SelectedIndex }; var result = db.PlaylistTracks.Where(pt => pt.PlaylistId == selectedPlaylist.PlaylistId && pt.TrackId == checkedListBoxTracks.SelectedIndex); if (result.ToArray().Length > 0) { MessageBox.Show("Track already exists!"); return; } db.PlaylistTracks.Add(newPlaylistTrack); db.SaveChanges(); } }