Esempio n. 1
0
        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);
            }
        }
        private void DGVPlaylistForm_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            using (var db = new everyloopContext())
            {
                if (!int.TryParse(DGVPlaylistForm.Rows[e.RowIndex].Cells["PlaylistId"].Value.ToString(), out int playlistId))
                {
                    return;
                }

                var playlistTracks = db.PlaylistTracks
                                     .Where(x => x.PlaylistId == playlistId)
                                     .Include(x => x.Playlist)
                                     .Include(x => x.Track).ThenInclude(x => x.Album)
                                     .ThenInclude(x => x.Artist)
                                     .Include(x => x.Track).ThenInclude(x => x.Genre);


                DGVTracks.DataSource = playlistTracks.Select(x => new
                {
                    Name   = x.Track.Name,
                    Artist = x.Track.Album.Artist.Name ?? "No artist",
                    Album  = x.Track.Album.Title,
                    Genre  = x.Track.Genre.Name
                }).ToList();
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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;
            }
        }
 private void SearchTracksButton_Click(object sender, EventArgs e)
 {
     using (var db = new everyloopContext())
     {
         var tracks = (from t in db.Tracks
                       where t.Name.ToLower() == SearchTracksBox.Text
                       join al in db.Albums
                       on t.AlbumId equals al.AlbumId
                       join ar in db.Artists
                       on al.ArtistId equals ar.ArtistId
                       join g in db.Genres
                       on t.GenreId equals g.GenreId
                       select new
         {
             Track = t.Name,
             Album = al.Title,
             Artist = ar.Name,
             Genre = g.Name
         }).ToList();
         try
         {
             DGVTracks.DataSource = tracks;
         }
         catch (Exception ex)
         {
             MessageBox.Show(Convert.ToString(ex));
         }
     }
 }
 private void ViewAllTracksButton_Click(object sender, EventArgs e)
 {
     using (var db = new everyloopContext())
     {
         var tracks = (from t in db.Tracks
                       join al in db.Albums
                       on t.AlbumId equals al.AlbumId
                       join ar in db.Artists
                       on al.ArtistId equals ar.ArtistId
                       join g in db.Genres
                       on t.GenreId equals g.GenreId
                       select new
         {
             Track = t.Name,
             Album = al.Title,
             Artist = ar.Name,
             Genre = g.Name
         }).ToList();
         try
         {
             DGVTracks.DataSource = tracks;
         }
         catch (Exception)
         {
             MessageBox.Show("Could not find data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Esempio n. 7
0
        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;
        }
Esempio n. 8
0
        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");
                }
            }
        }
        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();
            }
        }
        private void PlaylistForm_Load(object sender, EventArgs e)
        {
            using (var db = new everyloopContext())
            {
                try
                {
                    CurrentPlaylistBox.DataSource = db.Playlists.ToList();
                    TrackPlaylistBox.DataSource   = db.Playlists.ToList();

                    DGVPlaylistForm.DataSource = db.Playlists.ToList();
                    ShowAllTracks();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(Convert.ToString(ex));
                }
                CurrentPlaylistBox.Text          = "Playlist";
                CurrentPlaylistBox.DisplayMember = "Name";
                CurrentPlaylistBox.ValueMember   = "PlaylistId";

                TrackPlaylistBox.Text          = "Playlist";
                TrackPlaylistBox.DisplayMember = "Name";
                TrackPlaylistBox.ValueMember   = "PlaylistId";
            }
        }
        public void UpdateForm()
        {
            using (var db = new everyloopContext())
            {
                CurrentPlaylistBox.DataSource = db.Playlists.ToList();
                TrackPlaylistBox.DataSource   = db.Playlists.ToList();

                DGVPlaylistForm.DataSource = db.Playlists.ToList();
            }
        }
Esempio n. 12
0
 public void ShowTracks()
 {
     Console.WriteLine("\nAll songs \n");
     using (everyloopContext context = new everyloopContext())
     {
         List <Track> tracks = context.Tracks.ToList();
         foreach (var song in tracks)
         {
             Console.WriteLine($"ID:{song.TrackId} {song.Name}");
         }
     }
 }
Esempio n. 13
0
 public void ShowPlayLists()
 {
     Console.WriteLine("\nAll PlayLists \n");
     using (everyloopContext context = new everyloopContext())
     {
         List <Playlist> playlist = context.Playlists.ToList();
         foreach (var pl in playlist)
         {
             Console.WriteLine($"ID:{pl.PlaylistId} {pl.Name}");
         }
     }
 }
 private void ViewPlaylistsbutton_Click(object sender, EventArgs e)
 {
     using (var db = new everyloopContext())
     {
         try
         {
             DGVPlaylistForm.DataSource = db.Playlists.ToList();
         }
         catch (Exception ex)
         {
             MessageBox.Show(Convert.ToString(ex));
         }
     }
 }
Esempio n. 15
0
        public void ShowTracksInPlayList(int id)
        {
            using (everyloopContext context = new everyloopContext())
            {
                var list = context.PlaylistTracks.Where(x => x.PlaylistId == id).AsNoTracking();

                Console.WriteLine($"\nTracks in playlistID {id}\n");

                foreach (var pl in list)
                {
                    {
                        Console.WriteLine($"TrackID:{pl.TrackId}");
                    }
                }
            }
            return;
        }
Esempio n. 16
0
        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();
            }
        }
        public void ShowAllTracks()
        {
            using (var db = new everyloopContext())
            {
                var tracks = (from t in db.Tracks
                              join al in db.Albums
                              on t.AlbumId equals al.AlbumId
                              join ar in db.Artists
                              on al.ArtistId equals ar.ArtistId
                              join g in db.Genres
                              on t.GenreId equals g.GenreId
                              select new
                {
                    Track = t.Name,
                    Album = al.Title,
                    Artist = ar.Name,
                    Genre = g.Name
                }).ToList();


                DGVTracks.DataSource = tracks;
            }
        }
        private void ViewTracksButton_Click(object sender, EventArgs e)
        {
            var id     = Convert.ToInt32(CurrentPlaylistBox.SelectedValue);
            var tracks = new List <(Track track, Artist artist)>();

            using (var db = new everyloopContext())
            {
                var playlistTracks = db.PlaylistTracks
                                     .Where(x => x.PlaylistId == id)
                                     .Include(x => x.Playlist)
                                     .Include(x => x.Track).ThenInclude(x => x.Album)
                                     .ThenInclude(x => x.Artist)
                                     .Include(x => x.Track).ThenInclude(x => x.Genre);


                DGVPlaylistForm.DataSource = playlistTracks.Select(x => new
                {
                    Name   = x.Track.Name,
                    Artist = x.Track.Album.Artist.Name ?? "No artist",
                    Album  = x.Track.Album.Title,
                    Genre  = x.Track.Genre.Name
                }).ToList();
            }
        }