private void AddSongToPlaylist() { Console.Clear(); SongsRepository songsRepo = new SongsRepository(Constants.SongsDirectory); List <Song> songsDb = songsRepo.GetAll(); foreach (Song song in songsDb) { Console.WriteLine("Song ID: " + song.Id); Console.WriteLine("Song Title: " + song.Title); Console.WriteLine("Song ArtistName: " + song.ArtistName); Console.WriteLine("Song Year: " + song.Year); Console.WriteLine("=================================================="); } Console.Write("Song ID: "); int songIdInput = Int32.Parse(Console.ReadLine()); List <Song> songDb = songsRepo.GetAll((song => song.Id == songIdInput)); if (songDb[0] == null) { Console.WriteLine("Cannot find song"); Console.ReadKey(true); return; } Console.Clear(); PlaylistsRepository playlistsRepo = new PlaylistsRepository(Constants.PlaylistsDirectory); List <Playlist> playlistsDb = playlistsRepo.GetAll(playlist => AuthenticationService.LoggedUser.Id == playlist.ParentUserId); foreach (Playlist playlist in playlistsDb)// user's playlists { Console.WriteLine("Playlist ID: " + playlist.Id); Console.WriteLine("Playlist Name: " + playlist.Name); Console.WriteLine("Playlist Description: " + playlist.Description); Console.WriteLine("Playlist Is public?: " + playlist.IsPublic); Console.WriteLine("===================================================="); } Console.Write("Playlist ID: "); int playlistIdInput = Int32.Parse(Console.ReadLine()); if (playlistsDb.Count == 0) { Console.WriteLine("Playlist not found"); Console.ReadKey(true); return; } playlistsDb = playlistsDb.Where(playlist => playlist.Id == playlistIdInput).ToList(); PlaylistsSongs playlistsSongs = new PlaylistsSongs(songDb[0], playlistsDb[0]); PlaylistsSongsRepository playlistsSongsRepo = new PlaylistsSongsRepository(Constants.PlaylistsSongsDirectory); playlistsSongsRepo.Save(playlistsSongs); Console.WriteLine("Song saved successfully to playlist!"); Console.ReadKey(true); }
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 static bool ViewSongs(bool calledFromSongsView = false) { SongsRepository songsRepo = new SongsRepository(Constants.SongsPath); SongsArtistsRepository songsArtistsRepo = new SongsArtistsRepository(Constants.SongsArtistsPath); ArtistsRepository artistsRepo = new ArtistsRepository(Constants.ArtistsPath); List <Song> songs = songsRepo.GetAll(); Console.Clear(); if (songs.Count == 0) { Console.WriteLine("There are no songs in the system yet!"); Console.ReadKey(true); return(false); } 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("********************************"); } if (calledFromSongsView) { Console.ReadKey(true); } return(true); }
public ActionResult Index() { var songs = _songsRepository .GetAll() .Select(s => new SongWithAlbumViewModel { Song = s, AlbumTitle = s.Album.Title }); var result = songs.ToList(); return(View(result)); }
private void GetAll() { Console.Clear(); List <Song> songs = _songsRepository.GetAll(this.playlist.Id); foreach (Song song in songs) { Console.WriteLine("\tSong ID : " + song.Id); Console.WriteLine("\tName : " + song.ArtistName); Console.WriteLine("\tTitle : " + song.Title); Console.WriteLine("\tYear : " + song.Year); Console.WriteLine("___________________________________"); } Console.ReadKey(true); }
private void GetAll() { Console.Clear(); SongsRepository songsRepository = new SongsRepository("songs.txt"); List <Entity.Song> songs = songsRepository.GetAll(AuthenticationService.LoggedUser.Id); foreach (Entity.Song song in songs) { Console.WriteLine("ID:" + song.Id); Console.WriteLine("Title :" + song.Title); Console.WriteLine("Artist Name :" + song.ArtistName); Console.WriteLine("Year :" + song.Year + "y"); Console.WriteLine("------------------------------------"); } Console.ReadKey(true); }
private void GetAll() { Console.Clear(); SongsRepository songsRepository = new SongsRepository(Properties.Settings.Default.FileSongs); UsersRepository usersRepository = new UsersRepository(Properties.Settings.Default.FileUsers); List <Playlist> playlist = _playlistRepository.GetAll(); List <Song> songs = songsRepository.GetAll(); List <User> users = usersRepository.GetAll(); foreach (Playlist playlistitem in playlist) { var owners = users.Where(x => playlistitem.UserOwnerId.Equals(x.Id)).ToList(); foreach (User ownerUser in owners) { Console.WriteLine("_______________________________________"); Console.WriteLine("\tOwner Username: "******"\tPlaylist ID : " + playlistitem.Id); Console.WriteLine("\tPlaylist Name : " + playlistitem.Name); Console.WriteLine("\tPlaylist Public : " + playlistitem.IsPublic); Console.WriteLine("_______________________________________"); var songsForThisPlayList = songs.Where(x => playlistitem.SongsIts.Contains(x.Id)).ToList(); foreach (Song songitem in songsForThisPlayList) { Console.WriteLine("---------------------------------------"); Console.WriteLine("\tSong ID : " + songitem.Id); Console.WriteLine("\tSong Name : " + songitem.ArtistName); Console.WriteLine("\tSong Title : " + songitem.Title); Console.WriteLine("\tSong Year : " + songitem.Year); } Console.WriteLine("---------------------------------------"); Console.WriteLine("\n"); } 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); }
public void EditSong() { bool hasSongs = ViewSongs(); if (hasSongs == false) { return; } Console.WriteLine(); int editId; bool isIntId; do { Console.Write("Enter song id to edit: "); isIntId = int.TryParse(Console.ReadLine(), out editId); if (isIntId == false) { Console.WriteLine("IDs can only be integer numbers. Try again!!"); Console.ReadKey(true); } }while (isIntId == false); SongsRepository songRepo = new SongsRepository(Constants.SongsPath); Song song = songRepo.GetAll(s => s.Id == editId).FirstOrDefault(); if (song == null) { Console.WriteLine("No song with that Id exists!"); Console.ReadKey(true); return; } Console.Clear(); Console.WriteLine("Old song title: {0}", song.Title); string newSongTitle; bool isEmptyName; do { Console.Write("New song title: "); newSongTitle = Console.ReadLine(); isEmptyName = string.IsNullOrWhiteSpace(newSongTitle); if (isEmptyName) { Console.WriteLine("Song name cannot be empty. Try again!!"); Console.ReadKey(); } } while (isEmptyName == true); song.Title = newSongTitle; short newSongReleaseYear; bool isIntYear = false; bool isCurrentOrPastYear = false; Console.WriteLine("Old song release year: {0}", song.Year); do { Console.Write("New song release year: "); isIntYear = short.TryParse(Console.ReadLine(), out newSongReleaseYear); if (isIntYear == false) { Console.WriteLine("Song release year can only be an integer number. Try Again!!"); Console.ReadKey(); } if (DateTime.Now.Year >= newSongReleaseYear) { isCurrentOrPastYear = true; } if (isCurrentOrPastYear == false) { Console.WriteLine("Song release year cannot be after the current year. Try again!!"); Console.ReadKey(true); } } while (isIntYear == false || isCurrentOrPastYear == false); song.Year = newSongReleaseYear; songRepo.Save(song); Console.WriteLine("Song edited successfully!"); Console.ReadKey(true); }
public static void Main(string[] args) { // Connecting to database and pulling data var musiciansRepository = new MusiciansRepository(); var albumsRepository = new AlbumsRepository(); var songsRepository = new SongsRepository(); var albumsSongsRepository = new AlbumsSongsRepository(); const string connectionString = "Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=Music;Integrated Security=true;MultipleActiveResultSets=true;"; using (var connection = new SqlConnection(connectionString)) { musiciansRepository.AddList(connection.Query <Musician>("SELECT * FROM Musician").ToList()); albumsRepository.AddList(connection.Query <Album>("SELECT * FROM Album").ToList()); songsRepository.AddList(connection.Query <Song>("SELECT * FROM Song").ToList()); albumsSongsRepository.AddList(connection.Query <AlbumSong>("SELECT * FROM AlbumSong").ToList()); } musiciansRepository.CreateRelations(); albumsRepository.CreateRelations(); // Task 1 NewTask("Task 1"); Console.WriteLine("All musicians ordered by name: "); musiciansRepository.GetAll() .OrderBy(musician => musician.Name) .ToList() .ForEach(musician => Console.WriteLine(musician.ToString())); // Task 2 NewTask("Task 2"); Console.Write("Choose nationality (0-1): "); var selectedNationality = (Nationalities)int.Parse(Console.ReadLine()); musiciansRepository.GetAll() .Where(musician => musician.Nationality == selectedNationality) .ToList() .ForEach(musician => Console.WriteLine(musician.ToString())); // Task 3 NewTask("Task 3"); var groupedAlbumsRepository = albumsRepository.GetAll() .GroupBy(album => album.ReleaseDate.Year) .ToList(); groupedAlbumsRepository.ForEach(albumGroup => { Console.WriteLine($"{albumGroup.Key}:"); albumGroup.ToList().ForEach(album => Console.WriteLine(album.ToString())); }); // Task 4 NewTask("Task 4"); Console.Write("Input album name: "); var selectedText = Console.ReadLine(); Console.WriteLine("All albums containing selected text: "); albumsRepository.GetAll() .Where(album => selectedText != null && album.Name.Contains(selectedText)) .ToList() .ForEach(album => Console.WriteLine(album.ToString())); // Task 5 NewTask("Task 5"); Console.WriteLine("Duration of all albums: "); albumsRepository.GetAll() .ForEach(album => Console.WriteLine($"{album.Name}: {album.Duration() / 60} minutes and {album.Duration() % 60} seconds")); // Task 6 NewTask("Task 6"); Console.Write("Input name of the song: "); var selectedSong = Console.ReadLine(); var selectedSongAsSong = songsRepository.GetAll().FirstOrDefault(song => selectedSong != null && song.Name.Contains(selectedSong)); Console.WriteLine("All albums with selected song: "); albumsRepository.GetAll() .Where(album => album.SongsList.Contains(selectedSongAsSong)) .ToList() .ForEach(album => Console.WriteLine(album.ToString())); // Task 7 NewTask("Task 7"); Console.Write("Input musician name: "); var selectedMusician = Console.ReadLine(); Console.Write("Input release year: "); var selectedReleaseYear = int.Parse(Console.ReadLine()); albumsRepository.GetAll() .Where(album => selectedMusician != null && (album.Musician.Name.Contains(selectedMusician) && album.ReleaseDate.Year > selectedReleaseYear)) .ToList() .ForEach(album => album.SongsList.ForEach(song => Console.WriteLine(song.ToString()))); }
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); }