protected override void ViewMoreLogic(int id) { PlaylistsSongsRepository playlistsSongsRepo = new PlaylistsSongsRepository(Constants.PlaylistsSongsDirectory); List <PlaylistsSongs> playlistsSongs = playlistsSongsRepo.GetAll(playlistsong => playlistsong.PlaylistId == id); if (playlistsSongs.Count == 0) { Console.WriteLine("This playlist doesn't have any songs in it!"); return; } List <int> songsIds = new List <int>(); foreach (PlaylistsSongs playlistSong in playlistsSongs) //gets the song ids for the chosen playlist { songsIds.Add(playlistSong.SongId); } SongsRepository songsRepo = new SongsRepository(Constants.SongsDirectory); List <Song> songs = new List <Song>(); foreach (int songId in songsIds) //gets the actual songs from the playlist { songs.Add(songsRepo.GetById(songId)); } Console.WriteLine("Songs"); foreach (Song song in songs) { Console.WriteLine("Song ID: " + song.Id); Console.WriteLine("Song Title: " + song.Title); Console.WriteLine("Song Artist Name: " + song.ArtistName); Console.WriteLine("Song Year: " + song.Year); Console.WriteLine("============================================"); } }
public void DeleteArtist() { ViewArtists(); Console.WriteLine(); InputId: Console.Write("Enter artist id to delete: "); int deleteId; bool isInt = int.TryParse(Console.ReadLine(), out deleteId); while (isInt == false) { Console.WriteLine("IDs can only be integer numbers. Try again!!"); Console.ReadKey(true); goto InputId; } ArtistsRepository artistsRepo = new ArtistsRepository(Constants.ArtistsPath); Artist artist = artistsRepo.GetAll(a => a.Id == deleteId).FirstOrDefault(); if (artist == null) { Console.WriteLine("No artist with that Id exists in the system yet!"); Console.ReadKey(true); return; } SongsArtistsRepository songsArtistsRepo = new SongsArtistsRepository(Constants.SongsArtistsPath); List <SongsArtists> songsArtistsEntities = songsArtistsRepo.GetAll(sae => sae.ArtistId == deleteId); SongsRepository songsRepo = new SongsRepository(Constants.SongsPath); List <Song> songs = new List <Song>(); foreach (SongsArtists songsArtistsEntity in songsArtistsEntities) { Song song = songsRepo.GetAll(s => s.Id == songsArtistsEntity.SongId).FirstOrDefault(); songs.Add(song); } PlaylistsSongsRepository playlistsSongsRepo = new PlaylistsSongsRepository(Constants.PlaylistsSongsPath); List <PlaylistsSongs> playlistsSongsEntities = new List <PlaylistsSongs>(); foreach (SongsArtists songsArtistsEntity in songsArtistsEntities) { PlaylistsSongs playlistSongEntity = playlistsSongsRepo.GetAll(pse => pse.SongId == songsArtistsEntity.SongId).FirstOrDefault(); playlistsSongsEntities.Add(playlistSongEntity); } foreach (PlaylistsSongs playlistsSongsEntity in playlistsSongsEntities) { playlistsSongsRepo.Delete(playlistsSongsEntity); } foreach (Song song in songs) { songsRepo.Delete(song); } artistsRepo.Delete(artist); Console.WriteLine("Artist deleted successfully!"); Console.ReadKey(true); }
public void DeletePlaylist() { ViewUserPlaylists(); Console.WriteLine(); Console.Write("Enter id to delete: "); int deleteId = 0; int currentUserId = AuthenticationService.LoggedUser.Id; bool isIntId = int.TryParse(Console.ReadLine(), out deleteId); while (isIntId == false) { Console.WriteLine("Id can only be an integer number. Try again!!"); Console.ReadKey(); Console.Write("Enter id to delete: "); isIntId = int.TryParse(Console.ReadLine(), out deleteId); } UsersPlaylistsRepository usersPlaylistsRepo = new UsersPlaylistsRepository(Constants.UsersPlaylistsPath); PlaylistsRepository playlistsRepo = new PlaylistsRepository(Constants.PlaylistsPath); UsersPlaylists usersPlaylistsEntity = usersPlaylistsRepo.GetAll(upe => upe.PlaylistId == deleteId && upe.UserId == currentUserId) .FirstOrDefault(); if (usersPlaylistsEntity == null) { Console.WriteLine("Playlist with id {0} does not exist or you have no rights to delete!", deleteId); Console.ReadKey(); return; } PlaylistsSongsRepository playlistsSongsRepo = new PlaylistsSongsRepository(Constants.PlaylistsSongsPath); List <PlaylistsSongs> playlistsSongsEntities = playlistsSongsRepo.GetAll(pse => pse.PlaylistId == deleteId); foreach (PlaylistsSongs playlistsSongsEntity in playlistsSongsEntities) { playlistsSongsRepo.Delete(playlistsSongsEntity); } Playlist playlistToDelete = playlistsRepo.GetAll(p => p.Id == deleteId).FirstOrDefault(); usersPlaylistsRepo.Delete(usersPlaylistsEntity); playlistsRepo.Delete(playlistToDelete); Console.WriteLine("Playlist successfully deleted!"); Console.ReadKey(true); }
public void DeleteSong() { bool hasSongs = ViewSongs(); //TODO: Refactore with do...while loop or simple while loop like in the bookmarked while loop. if (hasSongs == false) { return; } Console.WriteLine(); Console.Write("Enter id to delete: "); int deleteId = Convert.ToInt32(Console.ReadLine()); SongsArtistsRepository songsArtistsRepo = new SongsArtistsRepository(Constants.SongsArtistsPath); List <SongsArtists> songsArtistsEntities = songsArtistsRepo.GetAll(sa => sa.SongId == deleteId); foreach (SongsArtists songArtistEntity in songsArtistsEntities) { songsArtistsRepo.Delete(songArtistEntity); } SongsRepository songsRepo = new SongsRepository(Constants.SongsPath); Song songToDelete = songsRepo.GetAll(s => s.Id == deleteId).FirstOrDefault(); if (songToDelete == null) { Console.WriteLine("There is no song with that Id."); Console.ReadKey(true); return; } PlaylistsSongsRepository playlistsSongsRepo = new PlaylistsSongsRepository(Constants.PlaylistsSongsPath); List <PlaylistsSongs> playlistsSongsEntities = playlistsSongsRepo.GetAll(pse => pse.SongId == deleteId); foreach (PlaylistsSongs playlistSongsEntity in playlistsSongsEntities) { playlistsSongsRepo.Delete(playlistSongsEntity); } songsRepo.Delete(songToDelete); Console.WriteLine("Song deleted successfully!"); Console.ReadKey(true); }
private void DeleteSongFromPlaylist() { Console.Clear(); PlaylistsRepository playlistRepo = new PlaylistsRepository(Constants.PlaylistsDirectory); List <Playlist> playlists = playlistRepo.GetAll(playlist => playlist.ParentUserId == AuthenticationService.LoggedUser.Id); if (playlists.Count == 0) { Console.WriteLine("You don't have any playlists"); Console.ReadKey(true); return; } foreach (Playlist playlist in playlists) { Console.WriteLine("Playlist ID: " + playlist.Id); Console.WriteLine("Playlist Name: " + playlist.Name); Console.WriteLine("Playlist Description: " + playlist.Description); Console.WriteLine("=============================================================="); } Console.Write("Playlist ID: "); int playlistInputId = Int32.Parse(Console.ReadLine()); if (!playlists.Any(playlist => playlist.Id == playlistInputId)) { Console.WriteLine("Playlist not found!"); Console.ReadKey(true); return; } PlaylistsSongsRepository playlistsSongsRepo = new PlaylistsSongsRepository(Constants.PlaylistsSongsDirectory); List <PlaylistsSongs> playlistsSongs = playlistsSongsRepo.GetAll(playlistSong => playlistSong.PlaylistId == playlistInputId); Console.Clear(); if (playlistsSongs.Count == 0) { Console.WriteLine("This playlist doesn't have any songs!"); Console.ReadKey(true); return; } SongsRepository songsRepo = new SongsRepository(Constants.SongsDirectory); List <Song> songs = new List <Song>(); foreach (PlaylistsSongs playlistSong in playlistsSongs) { songs.Add(songsRepo.GetById(playlistSong.SongId)); } foreach (Song song in songs) { Console.WriteLine("Song ID: " + song.Id); Console.WriteLine("Song Title: " + song.Title); Console.WriteLine("Song Artist Name: " + song.ArtistName); Console.WriteLine("Song Year: " + song.Year); Console.WriteLine("=========================================================="); } Console.Write("Song ID: "); int songInputId = Int32.Parse(Console.ReadLine()); bool IsSongExist = playlistsSongsRepo.GetAll(playlistSong => playlistSong.PlaylistId == playlistInputId && playlistSong.SongId == songInputId).Count > 0; if (!IsSongExist) { Console.WriteLine("Song not found"); Console.ReadKey(true); return; } playlistsSongsRepo.Delete(playlistSong => playlistSong.PlaylistId == playlistInputId && playlistSong.SongId == songInputId); Console.WriteLine("Song deleted successfully from the playlist"); Console.ReadKey(true); }
public void ViewPublicPlaylists() { PlaylistsRepository playlistsRepo = new PlaylistsRepository(Constants.PlaylistsPath); List <Playlist> playlists = playlistsRepo.GetAll(); IEnumerable <Playlist> filteredPlaylists = playlists.Where(p => p.IsPublic == true); Console.Clear(); foreach (Playlist playlist in filteredPlaylists) { Console.WriteLine("*************************************"); Console.WriteLine("Id: {0}", playlist.Id); Console.WriteLine("Playlist name: {0}", playlist.Name); if (string.IsNullOrWhiteSpace(playlist.Description) == false) { Console.WriteLine("Description: {0}", playlist.Description); } Console.WriteLine("*************************************"); } Console.WriteLine(); Console.Write("Enter playlist id to see: "); int playlistId; bool isIntPlaylistId = int.TryParse(Console.ReadLine(), out playlistId); while (isIntPlaylistId == false) { Console.WriteLine("Playlist id can only be an integer number!"); Console.ReadKey(); Console.Write("Enter playlist id to see: "); isIntPlaylistId = int.TryParse(Console.ReadLine(), out playlistId); } PlaylistsSongsRepository playlistsSongsRepo = new PlaylistsSongsRepository(Constants.PlaylistsSongsPath); SongsArtistsRepository songsArtistsRepo = new SongsArtistsRepository(Constants.SongsArtistsPath); ArtistsRepository artistsRepo = new ArtistsRepository(Constants.ArtistsPath); SongsRepository songsRepo = new SongsRepository(Constants.SongsPath); List <PlaylistsSongs> playlistsSongsEntities = playlistsSongsRepo.GetAll(pse => pse.PlaylistId == playlistId); List <Song> songs = new List <Song>(); foreach (PlaylistsSongs playlistsSongsEntity in playlistsSongsEntities) { Song song = songsRepo.GetAll(s => s.Id == playlistsSongsEntity.SongId).FirstOrDefault(); songs.Add(song); } Console.Clear(); foreach (Song song in songs) { Console.WriteLine("********************************"); Console.WriteLine("Id: {0}", song.Id); Console.WriteLine("Song title: {0}", song.Title); Console.WriteLine("Song release year: {0}", song.Year); List <SongsArtists> songsArtists = songsArtistsRepo.GetAll(sa => sa.SongId == song.Id); List <Artist> artists = new List <Artist>(); foreach (SongsArtists songArtistItem in songsArtists) { int artistId = songArtistItem.ArtistId; Artist artist = artistsRepo.GetAll(a => a.Id == songArtistItem.ArtistId).FirstOrDefault(); artists.Add(artist); } if (artists.Count == 1) { Console.WriteLine("Artist: {0}", artists[0].Name); } else { Console.Write("Artists: "); int end = artists.Count - 1; for (int i = 0; i < end; i++) { Console.WriteLine("{0}, ", artists[i].Name); } Console.WriteLine(artists[end]); } Console.WriteLine("********************************"); } Console.ReadKey(true); }
public void ViewSpecificPlaylist() { ViewUserPlaylists(); Console.WriteLine(); Console.Write("Enter playlist id to view: "); int currentUserId = AuthenticationService.LoggedUser.Id; int playlistId; bool isIntPlaylistId = int.TryParse(Console.ReadLine(), out playlistId); while (isIntPlaylistId == false) { Console.WriteLine("Id can only be an integer number"); Console.Write("Enter playlist id to view: "); isIntPlaylistId = int.TryParse(Console.ReadLine(), out playlistId); } UsersPlaylistsRepository usersPlaylistsRepo = new UsersPlaylistsRepository(Constants.UsersPlaylistsPath); bool hasRightsToShare = usersPlaylistsRepo.EntityExists(upe => upe.PlaylistId == playlistId && upe.UserId == currentUserId); if (hasRightsToShare == false) { Console.WriteLine("Playlist does not exist or you have no rights to view!"); Console.ReadKey(true); return; } PlaylistsSongsRepository playlistsSongsRepo = new PlaylistsSongsRepository(Constants.PlaylistsSongsPath); List <PlaylistsSongs> playlistsSongsEntities = playlistsSongsRepo.GetAll(pse => pse.PlaylistId == playlistId); SongsRepository songsRepo = new SongsRepository(Constants.SongsPath); SongsArtistsRepository songsArtistsRepo = new SongsArtistsRepository(Constants.SongsArtistsPath); ArtistsRepository artistsRepo = new ArtistsRepository(Constants.ArtistsPath); List <Song> songs = new List <Song>(); foreach (PlaylistsSongs playlistsSongsEntity in playlistsSongsEntities) { Song song = songsRepo.GetAll(s => s.Id == playlistsSongsEntity.SongId).FirstOrDefault(); songs.Add(song); } if (songs.Count == 0) { Console.WriteLine("Playlist empty!"); Console.ReadKey(true); return; } Console.Clear(); foreach (Song song in songs) { Console.WriteLine("********************************"); Console.WriteLine("Id: {0}", song.Id); Console.WriteLine("Song title: {0}", song.Title); Console.WriteLine("Song release year: {0}", song.Year); List <SongsArtists> songsArtists = songsArtistsRepo.GetAll(sa => sa.SongId == song.Id); List <Artist> artists = new List <Artist>(); foreach (SongsArtists songArtistItem in songsArtists) { int artistId = songArtistItem.ArtistId; Artist artist = artistsRepo.GetAll(a => a.Id == songArtistItem.ArtistId).FirstOrDefault(); artists.Add(artist); } if (artists.Count == 1) { Console.WriteLine("Artist: {0}", artists[0].Name); } else { Console.Write("Artists: "); int end = artists.Count - 1; for (int i = 0; i < end; i++) { Console.WriteLine("{0}, ", artists[i].Name); } Console.WriteLine(artists[end]); } Console.WriteLine("********************************"); } Console.ReadKey(true); }
public void RemoveSongFromPlaylist() { ViewUserPlaylists(); Console.WriteLine(); Console.Write("Enter id of playlist: "); int playlistId; bool isIntPlaylistId = int.TryParse(Console.ReadLine(), out playlistId); while (isIntPlaylistId == false) { Console.WriteLine("Id can only be an integer number. Try again!!"); Console.ReadKey(); Console.Write("Enter id of playlist: "); isIntPlaylistId = int.TryParse(Console.ReadLine(), out playlistId); } UsersPlaylistsRepository usersPlaylistsRepo = new UsersPlaylistsRepository(Constants.UsersPlaylistsPath); int currentUserId = AuthenticationService.LoggedUser.Id; if (usersPlaylistsRepo.EntityExists(upe => upe.PlaylistId == playlistId && upe.UserId == currentUserId) == false) { Console.WriteLine("Playlist does not exist exist or you have no rights to add songs to it!"); Console.ReadKey(true); return; } PlaylistsSongsRepository playlistsSongsRepo = new PlaylistsSongsRepository(Constants.PlaylistsSongsPath); List <PlaylistsSongs> playlistsSongsEntities = playlistsSongsRepo.GetAll(pse => pse.PlaylistId == playlistId); SongsRepository songsRepo = new SongsRepository(Constants.SongsPath); SongsArtistsRepository songsArtistsRepo = new SongsArtistsRepository(Constants.SongsArtistsPath); ArtistsRepository artistsRepo = new ArtistsRepository(Constants.ArtistsPath); List <Song> songs = new List <Song>(); foreach (PlaylistsSongs playlistSongsEntity in playlistsSongsEntities) { Song song = songsRepo.GetAll(s => s.Id == playlistSongsEntity.SongId).FirstOrDefault(); songs.Add(song); } Console.Clear(); foreach (Song song in songs) { Console.WriteLine("********************************"); Console.WriteLine("Id: {0}", song.Id); Console.WriteLine("Song title: {0}", song.Title); Console.WriteLine("Song release year: {0}", song.Year); List <SongsArtists> songsArtists = songsArtistsRepo.GetAll(sa => sa.SongId == song.Id); List <Artist> artists = new List <Artist>(); foreach (SongsArtists songArtistItem in songsArtists) { int artistId = songArtistItem.ArtistId; Artist artist = artistsRepo.GetAll(a => a.Id == songArtistItem.ArtistId).FirstOrDefault(); artists.Add(artist); } if (artists.Count == 1) { Console.WriteLine("Artist: {0}", artists[0].Name); } else { Console.Write("Artists: "); int end = artists.Count - 1; for (int i = 0; i < end; i++) { Console.WriteLine("{0}, ", artists[i].Name); } Console.WriteLine(artists[end]); } Console.WriteLine("********************************"); } Console.WriteLine(); Console.Write("Select song id to remove from the playlist: "); int songId; bool isIntSongId = int.TryParse(Console.ReadLine(), out songId); while (isIntSongId == false) { Console.WriteLine("Id can only be an integer number. Try again!!"); Console.ReadKey(); Console.Write("Select song id to remove from the playlist: "); isIntSongId = int.TryParse(Console.ReadLine(), out songId); } PlaylistsSongs playlistsSongsEntity = playlistsSongsRepo.GetAll(pse => pse.PlaylistId == playlistId && pse.SongId == songId).FirstOrDefault(); if (playlistsSongsEntity == null) { Console.WriteLine("Song does not exist in that playlist or you have no rights to remove!"); Console.ReadKey(true); return; } playlistsSongsRepo.Delete(playlistsSongsEntity); Console.WriteLine("Song successfully removed from playlist!"); Console.ReadKey(true); }