Ejemplo n.º 1
0
 private void btAlbumsSave_Click(object sender, EventArgs e)
 {
     if (cbAlbums.Text != "")
     {
         using (MusicAppContext ctx = new MusicAppContext())
         {
             Album  AlbumToSave = new Album();
             bool   newSong     = false;
             string msg         = " updated";
             if ((cbAlbums.Text != "") && ((cbAlbums.SelectedItem as ComboboxItem) != null))
             {
                 ComboboxItem AlbumSelected = (cbSongs.SelectedItem as ComboboxItem);
                 AlbumToSave = ctx.Albums.FirstOrDefault(s => s.AlbumId == AlbumSelected.Key);
             }
             else
             {
                 newSong = true;
                 msg     = " created";
             }
             AlbumToSave.Name = cbAlbums.Text;
             if (newSong)
             {
                 ctx.Albums.Add(AlbumToSave);
             }
             ctx.SaveChanges();
             MessageBox.Show(cbAlbums.Text + msg);
         }
         LoadRefresh();
     }
 }
Ejemplo n.º 2
0
 private void btPlayListDelete_Click(object sender, EventArgs e)
 {
     if ((cbPlaylists.Text != null) && (cbPlaylists.SelectedItem as ComboboxItem) != null)
     {
         ComboboxItem playlistSelected = cbPlaylists.SelectedItem as ComboboxItem;
         using (MusicAppContext ctx = new MusicAppContext())
         {
             Playlist playlistToDelete = ctx.Playlists.FirstOrDefault(s => s.PlaylistId == playlistSelected.Key);
             ctx.Playlists.Remove(playlistToDelete);
             ctx.SaveChanges();
         }
         LoadRefresh();
     }
 }
Ejemplo n.º 3
0
 private void btAlbumsDelete_Click(object sender, EventArgs e)
 {
     if ((cbAlbums.Text != null) && (cbAlbums.SelectedItem as ComboboxItem) != null)
     {
         ComboboxItem albumSelected = cbAlbums.SelectedItem as ComboboxItem;
         using (MusicAppContext ctx = new MusicAppContext())
         {
             Album albumToDelete = ctx.Albums.FirstOrDefault(s => s.AlbumId == albumSelected.Key);
             ctx.Albums.Remove(albumToDelete);
             ctx.SaveChanges();
         }
         LoadRefresh();
     }
 }
Ejemplo n.º 4
0
 private void btSongsDelete_Click(object sender, EventArgs e)
 {
     if ((cbSongs.Text != null) && (cbSongs.SelectedItem as ComboboxItem) != null)
     {
         ComboboxItem songSelected = cbSongs.SelectedItem as ComboboxItem;
         using (MusicAppContext ctx = new MusicAppContext())
         {
             Song songToDelete = ctx.Songs.FirstOrDefault(s => s.SongId == songSelected.Key);
             ctx.Songs.Remove(songToDelete);
             ctx.SaveChanges();
         }
         LoadRefresh();
     }
 }
Ejemplo n.º 5
0
 private void btSongsSave_Click(object sender, EventArgs e)
 {
     if (cbSongs.Text != "")
     {
         bool   newSong = false;
         string msg     = " updated";
         using (MusicAppContext ctx = new MusicAppContext())
         {
             Song SongToSave = new Song();
             if ((cbSongs.Text != "") && ((cbSongs.SelectedItem as ComboboxItem) != null))
             {
                 ComboboxItem SongSelected = (cbSongs.SelectedItem as ComboboxItem);
                 SongToSave = ctx.Songs.FirstOrDefault(s => s.SongId == SongSelected.Key);
             }
             else
             {
                 newSong = true;
             }
             SongToSave.Title = cbSongs.Text;
             if ((cbAlbums.Text != "") && ((cbAlbums.SelectedItem as ComboboxItem) != null))
             {
                 ComboboxItem AlbumSelected = cbAlbums.SelectedItem as ComboboxItem;
                 Album        attachAlbum   = ctx.Albums.FirstOrDefault(a => a.AlbumId == AlbumSelected.Key);
                 if (SongToSave.Albums == null)
                 {
                     SongToSave.Albums = new List <Album>();
                 }
                 SongToSave.Albums.Add(attachAlbum);
             }
             if ((cbArtists.Text != "") && ((cbArtists.SelectedItem as ComboboxItem) != null))
             {
                 ComboboxItem artistSelected = cbArtists.SelectedItem as ComboboxItem;
                 Artist       artistToAdd    = ctx.Artists.FirstOrDefault(a => a.ArtistId == artistSelected.Key);
                 if (SongToSave.Artists == null)
                 {
                     SongToSave.Artists = new List <Artist>();
                 }
                 SongToSave.Artists.Add(artistToAdd);
             }
             if (newSong)
             {
                 ctx.Songs.Add(SongToSave);
                 msg = " created";
             }
             ctx.SaveChanges();
             MessageBox.Show(cbSongs.Text + msg);
         }
         LoadRefresh();
     }
 }
Ejemplo n.º 6
0
 private bool EmailFound(string email)
 {
     using (MusicAppContext ctx = new MusicAppContext())
     {
         if (ctx.Users.Any(u => u.Email.Trim() == regEmail))
         {
             return(true);
         }
         else
         {
             MessageBox.Show(email + " already exists");
         }
     }
     MessageBox.Show("connection to database failed");
     return(false);
 }
Ejemplo n.º 7
0
 private bool LoginSuccess(string email, string password)
 {
     using (MusicAppContext ctx = new MusicAppContext())
     {
         var currentUser = ctx.Users.FirstOrDefault(u => (u.Email.Trim() == email) && (u.Password.Trim() == password));
         if (currentUser != null)
         {
             this.Hide();
             PlaylistForm newPlaylistForm = new PlaylistForm(currentUser.UserId);
             MessageBox.Show("logged in successfull");
             newPlaylistForm.Show();
             return(true);
         }
     }
     MessageBox.Show("connection to database failed or user not found");
     return(false);
 }
Ejemplo n.º 8
0
 private void RefreshPlaylistGrid()
 {
     if ((cbPlaylists.Text != "") && ((cbPlaylists.SelectedItem as ComboboxItem) != null))
     {
         DataTable    dtSongsOfPlaylist = new DataTable();
         ComboboxItem selectedPlaylist  = (cbPlaylists.SelectedItem as ComboboxItem);
         dtSongsOfPlaylist.Columns.Add(new DataColumn("Song Title", typeof(string)));
         dtSongsOfPlaylist.Columns.Add(new DataColumn("Albums", typeof(string)));
         dtSongsOfPlaylist.Columns.Add(new DataColumn("Artists", typeof(string)));
         using (MusicAppContext ctx = new MusicAppContext())
         {
             var PlaylistWithSongs = ctx.Playlists.FirstOrDefault(p => p.PlaylistId == selectedPlaylist.Key);
             foreach (var Song in PlaylistWithSongs.Songs.ToList())
             {
                 List <string> newRow  = new List <string>();
                 string        albums  = "";
                 string        artists = "";
                 int           iCount  = 0;
                 newRow.Add(Song.Title);
                 foreach (var album in Song.Albums.ToList())
                 {
                     if (iCount++ > 0)
                     {
                         albums += ", ";
                     }
                     albums += album.Name;
                 }
                 newRow.Add(albums);
                 iCount = 0;
                 foreach (var artist in Song.Artists.ToList())
                 {
                     if (iCount++ > 0)
                     {
                         artists += ", ";
                     }
                     artists += artist.Name;
                 }
                 newRow.Add(artists);
                 dtSongsOfPlaylist.Rows.Add(newRow.ToArray());
             }
         }
         dgPlaylist.DataSource = dtSongsOfPlaylist;
     }
 }
Ejemplo n.º 9
0
 private void btAddToPlaylist_Click(object sender, EventArgs e)
 {
     if ((cbPlaylists.Text != null) && ((cbPlaylists.SelectedItem as ComboboxItem) != null))
     {
         if ((cbSongs.Text != null) && (cbSongs.SelectedItem as ComboboxItem) != null)
         {
             ComboboxItem songToAdd  = cbSongs.SelectedItem as ComboboxItem;
             ComboboxItem toPlaylist = cbPlaylists.SelectedItem as ComboboxItem;
             using (MusicAppContext ctx = new MusicAppContext())
             {
                 Playlist playlist = ctx.Playlists.FirstOrDefault(p => p.PlaylistId == toPlaylist.Key);
                 Song     song     = ctx.Songs.FirstOrDefault(s => s.SongId == songToAdd.Key);
                 playlist.Songs.Add(song);
                 ctx.SaveChanges();
             }
             RefreshPlaylistGrid();
         }
     }
 }
Ejemplo n.º 10
0
 private void btPlayListSave_Click(object sender, EventArgs e)
 {
     if (cbPlaylists.Text != "")
     {
         if (cbPlaylists.ValueMember == "")
         {
             using (MusicAppContext ctx = new MusicAppContext())
             {
                 Playlist newPlaylist = new Playlist();
                 newPlaylist.Name   = cbPlaylists.Text;
                 newPlaylist.UserId = CurrentUserId;
                 ctx.Playlists.Add(newPlaylist);
                 ctx.SaveChanges();
                 MessageBox.Show(cbPlaylists.Text + " created");
             }
             LoadRefresh();
         }
     }
 }
Ejemplo n.º 11
0
 private void btRegister_Click(object sender, EventArgs e)
 {
     if (ValidUser())
     {
         using (MusicAppContext ctx = new MusicAppContext())
         {
             User nieuwUser = new User()
             {
                 Firstname = regFirstName,
                 Lastname  = regLastName,
                 Email     = regEmail,
                 Password  = regPassword
             };
             ctx.Users.Add(nieuwUser);
             ctx.SaveChanges();
         }
         UserLoggedIn = LoginSuccess(regEmail, regPassword);
     }
     else
     {
         MessageBox.Show("Invalid user");
     }
 }
Ejemplo n.º 12
0
 private void btArtistsSave_Click(object sender, EventArgs e)
 {
     if (cbArtists.Text != "")
     {
         using (MusicAppContext ctx = new MusicAppContext())
         {
             Artist ArtistToSave = new Artist();
             bool   newArtist    = false;
             string msg          = " updated";
             if ((cbArtists.Text != "") && ((cbArtists.SelectedItem as ComboboxItem) != null))
             {
                 ComboboxItem ArtistSelected = (cbArtists.SelectedItem as ComboboxItem);
                 ArtistToSave = ctx.Artists.FirstOrDefault(s => s.ArtistId == ArtistSelected.Key);
             }
             else
             {
                 newArtist = true;
                 msg       = " created";
             }
             ArtistToSave.Name = cbArtists.Text;
             if ((cbSongs.Text != "") && ((cbSongs.SelectedItem as ComboboxItem) != null))
             {
                 ComboboxItem songSelected = cbSongs.SelectedItem as ComboboxItem;
                 Song         SongToArtist = ctx.Songs.FirstOrDefault(s => s.SongId == songSelected.Key);
                 ArtistToSave.Songs.Add(SongToArtist);
             }
             if (newArtist)
             {
                 ctx.Artists.Add(ArtistToSave);
             }
             ctx.SaveChanges();
             MessageBox.Show(cbArtists.Text + msg);
         }
         LoadRefresh();
     }
 }
Ejemplo n.º 13
0
        private void LoadRefresh()
        {
            using (MusicAppContext ctx = new MusicAppContext())
            {
                DataTable dtSongs     = new DataTable();
                DataTable dtPlaylists = new DataTable();

                cbPlaylists.Items.Clear();
                cbPlaylists.Text = "";
                cbAlbums.Items.Clear();
                cbAlbums.Text = "";
                cbSongs.Items.Clear();
                cbSongs.Text = "";
                cbArtists.Items.Clear();
                cbArtists.Text = "";
                var userPlaylists = ctx.Playlists.Where(p => p.UserId == CurrentUserId);
                foreach (Playlist playlist in userPlaylists)
                {
                    ComboboxItem newItem = new ComboboxItem(playlist.PlaylistId, playlist.Name);
                    cbPlaylists.Items.Add(newItem);
                }
                cbAlbums.Items.Clear();
                foreach (Album album in ctx.Albums)
                {
                    ComboboxItem newItem = new ComboboxItem(album.AlbumId, album.Name);
                    cbAlbums.Items.Add(newItem);
                }
                foreach (Song song in ctx.Songs)
                {
                    ComboboxItem newItem = new ComboboxItem(song.SongId, song.Title);
                    cbSongs.Items.Add(newItem);
                }
                foreach (Artist artist in ctx.Artists)
                {
                    ComboboxItem newItem = new ComboboxItem(artist.ArtistId, artist.Name);
                    cbArtists.Items.Add(newItem);
                }
                dtSongs.Columns.Add(new DataColumn("Song Title", typeof(string)));
                dtSongs.Columns.Add(new DataColumn("Albums", typeof(string)));
                dtSongs.Columns.Add(new DataColumn("Artists", typeof(string)));
                var SongsWithAlbums = ctx.Songs;
                foreach (var Song in SongsWithAlbums.ToList())
                {
                    List <string> newRow  = new List <string>();
                    string        albums  = "";
                    string        artists = "";
                    int           iCount  = 0;
                    newRow.Add(Song.Title);
                    foreach (var album in Song.Albums.ToList())
                    {
                        if (iCount++ > 0)
                        {
                            albums += ", ";
                        }
                        albums += album.Name;
                    }
                    newRow.Add(albums);
                    iCount = 0;
                    foreach (var artist in Song.Artists.ToList())
                    {
                        if (iCount++ > 0)
                        {
                            artists += ", ";
                        }
                        artists += artist.Name;
                    }
                    newRow.Add(artists);
                    dtSongs.Rows.Add(newRow.ToArray());
                }
                dgSongs.DataSource = dtSongs;
            }
        }