public void DeletePlaylist2(int id) { using (everyloopContext context = new everyloopContext()) { Playlist playlist = context.Playlists.FirstOrDefault(x => x.PlaylistId == id); List <Playlist> playlists = context.Playlists.OrderBy(x => x.PlaylistId).ToList(); if (!playlists.Contains(playlist)) { Console.WriteLine("The playlist does not exist!"); return; } context.SaveChanges(); var list = context.Playlists.Where(x => x.PlaylistId == playlist.PlaylistId); foreach (var PlaylistItem in list) { context.Playlists.Remove(PlaylistItem); } context.SaveChanges(); context.Playlists.Attach(playlist); context.Playlists.Remove(playlist); } }
private void AddTrackButton_Click(object sender, EventArgs e) { using (var db = new everyloopContext()) { var trackName = db.Tracks.SingleOrDefault(x => x.Name.ToLower() == TrackNameBox.Text.ToLower()); if (trackName == null) { MessageBox.Show("Could not find track", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var id = Convert.ToInt32(TrackPlaylistBox.SelectedValue); var trackNameId = trackName.TrackId; PlaylistTrack playlistTrack = db.PlaylistTracks.SingleOrDefault(x => x.TrackId == trackNameId && x.PlaylistId == id); if (playlistTrack != null) { MessageBox.Show("Track already added", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } db.PlaylistTracks.Add(new PlaylistTrack { PlaylistId = id, TrackId = trackNameId }); db.SaveChanges(); } }
public void DeletePlaylist() { ShowPlayLists(); Console.WriteLine(); Console.Write("Enter the Id of the playlist you want to remove: "); int id = int.Parse(Console.ReadLine()); using (everyloopContext context = new everyloopContext()) { PlaylistTrack playlist = context.PlaylistTracks.FirstOrDefault(x => x.PlaylistId == id); var list = context.PlaylistTracks.Where(x => x.PlaylistId == playlist.PlaylistId); foreach (var PlaylistItem in list) { context.PlaylistTracks.Remove(PlaylistItem); } context.SaveChanges(); context.PlaylistTracks.Attach(playlist); context.PlaylistTracks.Remove(playlist); DeletePlaylist2(id); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("The playlist " + playlist.PlaylistId + " was removed"); Console.ForegroundColor = ConsoleColor.Gray; } }
public void AddInstantTrack(int id) { Console.Write("Show list of tracks? Y/N: "); string yn = Console.ReadLine(); if (yn == "Y" || yn == "y") { ShowTracks(); } Console.Write("Type the track Id you want to add: "); int chosenTrackId = int.Parse(Console.ReadLine()); PlaylistTrack playlisttrack = new PlaylistTrack(); playlisttrack.TrackId = chosenTrackId; playlisttrack.PlaylistId = id; using (everyloopContext context = new everyloopContext()) { context.PlaylistTracks.Add(playlisttrack); context.SaveChanges(); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"\nTrackId: {playlisttrack.TrackId} has been added\n"); Console.ForegroundColor = ConsoleColor.Gray; }
public void RenamePlayList() { Console.WriteLine(); ShowPlayLists(); Console.Write("Enter the id of the playlist you want to rename: "); int chosenPlayListId = int.Parse(Console.ReadLine()); using (everyloopContext context = new everyloopContext()) { var result = context.Playlists.SingleOrDefault(playlist => playlist.PlaylistId == chosenPlayListId); if (result != null) { Console.Write("Enter the new name of the playlist: "); string newValue = Console.ReadLine(); result.Name = newValue; context.SaveChanges(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"\nRenamed to: {newValue}\n"); Console.ForegroundColor = ConsoleColor.Gray; } else { Console.WriteLine("The playlist does not appear in the database"); } } }
public void AddNewPlaylist() { Console.WriteLine(); Console.Write("Enter the name for the Playlist: "); string valueMusic = Console.ReadLine(); Playlist playlist = new Playlist(); playlist.Name = valueMusic; using (everyloopContext context = new everyloopContext()) { int ID = context.Playlists.OrderBy(x => x.PlaylistId).Last().PlaylistId + 1; playlist.PlaylistId = ID; context.Playlists.Add(playlist); context.SaveChanges(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nThe playlist " + playlist.Name + " Has been added!\n"); Console.ForegroundColor = ConsoleColor.Gray; AddInstantTrack(playlist.PlaylistId); } }
public void RemoveTrackInPlayList() { ShowPlayLists(); Console.Write("Type the id of the playlist you want to edit: "); int chosenPlayListId = int.Parse(Console.ReadLine()); ShowTracksInPlayList(chosenPlayListId); Console.Write("Type the track Id you want to remove: "); int chosenTrackId = int.Parse(Console.ReadLine()); using (everyloopContext context = new everyloopContext()) { PlaylistTrack playlisttrack = context.PlaylistTracks.FirstOrDefault(x => x.TrackId == chosenTrackId && x.PlaylistId == chosenPlayListId); List <PlaylistTrack> PlayListId = context.PlaylistTracks.OrderBy(x => x.PlaylistId).ToList(); List <PlaylistTrack> PlayListTrackId = context.PlaylistTracks.OrderBy(x => x.TrackId).ToList(); if (!PlayListId.Contains(playlisttrack) && !PlayListTrackId.Contains(playlisttrack)) { Console.WriteLine("The track didn't exist in this playlist"); return; } var list = context.PlaylistTracks.Where(x => x.TrackId == playlisttrack.TrackId && x.PlaylistId == playlisttrack.PlaylistId); foreach (var item in list) { context.PlaylistTracks.Remove(item); } context.SaveChanges(); context.PlaylistTracks.Attach(playlisttrack); context.PlaylistTracks.Remove(playlisttrack); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"\nTrackId {playlisttrack.TrackId} was removed\n"); Console.ForegroundColor = ConsoleColor.Gray; } }
private void AddPlaylistButton_Click(object sender, EventArgs e) { using (var db = new everyloopContext()) { if (db.Playlists.Any(x => x.Name.ToLower() == NewPlaylistNameBox.Text.ToLower())) { MessageBox.Show("Playlist already exist", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var plId = db.Playlists.Max(x => x.PlaylistId) + 1; var newPlaylist = new Playlist() { PlaylistId = plId, Name = NewPlaylistNameBox.Text, }; db.Add(newPlaylist); db.SaveChanges(); UpdateForm(); } }
private void DeletePlaylistButton_Click(object sender, EventArgs e) { using (var db = new everyloopContext()) { var item = CurrentPlaylistBox.SelectedValue; var id = Convert.ToInt32(item); var playlist = db.Playlists.SingleOrDefault(x => x.PlaylistId == id); var playlistTracks = db.PlaylistTracks.Where(x => x.PlaylistId == id); if (playlist == null) { MessageBox.Show("Playlist already removed", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } db.PlaylistTracks.RemoveRange(playlistTracks); db.Playlists.Remove(playlist); db.SaveChanges(); UpdateForm(); } }