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 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 AddSong()
        {
            string inputSongTitle;
            bool   isEmptyName = false;

            do
            {
                Console.Clear();
                Console.Write("Enter new song name: ");
                inputSongTitle = Console.ReadLine();
                isEmptyName    = (String.IsNullOrWhiteSpace(inputSongTitle));
                if (isEmptyName == true)
                {
                    Console.WriteLine("Song title cannot be empty. Try again!!");
                    Console.ReadKey(true);
                }
            }while (isEmptyName == true);

            short inputSongReleaseYear;
            bool  isShortYear;
            bool  isBeforeCurrentYear = false;

            do
            {
                Console.Write("Enter song's release year: ");
                isShortYear = short.TryParse(Console.ReadLine(), out inputSongReleaseYear);
                if (DateTime.Now.Year >= inputSongReleaseYear)
                {
                    isBeforeCurrentYear = true;
                }
                if (isShortYear == false)
                {
                    Console.WriteLine("Year can only be an integer number. Try again!!");
                    Console.ReadKey(true);
                }

                if (isBeforeCurrentYear == false)
                {
                    Console.WriteLine("Year should not be after the current year.");
                }
            } while (isShortYear == false || isBeforeCurrentYear == false);

            Song newSong = new Song();

            newSong.Title = inputSongTitle;
            newSong.Year  = inputSongReleaseYear;
            SongsRepository songsRepo = new SongsRepository(Constants.SongsPath);

            if (songsRepo.EntityExists(s => s.Title == inputSongTitle && s.Year == inputSongReleaseYear))
            {
                Console.WriteLine("The song already exists in the database!");
                Console.ReadKey(true);
            }
            int songId = songsRepo.Save(newSong);
            ArtistsRepository artistsRepo = new ArtistsRepository(Constants.ArtistsPath);
            List <Artist>     artists     = artistsRepo.GetAll();

            Console.Clear();
            int artistId;

            if (artists.Count == 0)
            {
                artistId = ArtistsView.AddArtist();
            }
            else
            {
                foreach (Artist artistEntity in artists)
                {
                    Console.WriteLine("************************************");
                    Console.WriteLine("Id: {0}", artistEntity.Id);
                    Console.WriteLine("Artist name: {0}", artistEntity.Name);
                    Console.WriteLine("************************************");
                }

                Console.WriteLine();
EnterArtistId:
                Console.Write("Enter new song's artist id (type \"0\" if not in the list): ");
                bool isInt = int.TryParse(Console.ReadLine(), out artistId);
                while (isInt == false)
                {
                    Console.WriteLine("IDs can only be integer numbers. Try Again!!");
                    Console.ReadKey(true);
                    goto EnterArtistId;
                }

                if (artistId == 0)
                {
                    artistId = ArtistsView.AddArtist();
                }
            }
            SongsArtists songArtistEntity = new SongsArtists();

            songArtistEntity.SongId   = songId;
            songArtistEntity.ArtistId = artistId;
            SongsArtistsRepository songsArtistsRepo = new SongsArtistsRepository(Constants.SongsArtistsPath);

            songsArtistsRepo.Save(songArtistEntity);
            Console.WriteLine("Song saved successfully!");
            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);
        }