internal string Delete(int id) { Song song = Get(id); _repo.Delete(id); return("deleted"); }
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 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 Delete() { SongsRepository songsRepository = new SongsRepository("songs.txt"); Console.Clear(); Console.WriteLine("Delete Task:"); Console.Write("Task Id: "); int taskId = Convert.ToInt32(Console.ReadLine()); Entity.Song song = songsRepository.GetById(taskId); if (song == null) { Console.WriteLine("Song not found!"); } else { songsRepository.Delete(song); Console.WriteLine("Song deleted successfully."); } Console.ReadKey(true); }
private void Delete() { Console.Clear(); Console.WriteLine("\tDelete Song : "); Console.Write("\tSong Id : "); int songId = Convert.ToInt32(Console.ReadLine()); IsEmptyValidation(ref songId); Song song = _songsRepository.GetById(songId); if (song == null) { Console.WriteLine("\tSong not found!"); } else { _songsRepository.Delete(song); Console.WriteLine("\n"); Console.WriteLine("\tSong deleted successfully."); } Console.ReadKey(true); }