public Form2(User currentUser) { InitializeComponent(); CurrentUser = currentUser; lbl_welcome.Text = $"Welcome {CurrentUser.FirstName} {CurrentUser.LastName}!"; cb_ChoosePlaylist.Hide(); lbl_choosePlaylist.Hide(); var context = new MusicAppContext(); var artistCollection = context.Artists.Select(a => new { Name = a.Name, Id = a.ArtistId }).ToList(); cb_Artists.DataSource = artistCollection; cb_Artists.DisplayMember = "Name"; cb_Artists.ValueMember = "Id"; var albumCollection = context.Albums.Include("Artist").Select(a => new { NameAndArtist = a.Name + " " + "by " + a.Artist.Name, Id = a.AlbumId }).ToList(); cb_Albums.DataSource = albumCollection; cb_Albums.DisplayMember = "NameAndArtist"; cb_Albums.ValueMember = "Id"; }
private void btn_login_Click(object sender, EventArgs e) { using (MusicAppContext context = new MusicAppContext()) { User user = context.Users.FirstOrDefault(u => u.Email == txtLoginEmail.Text); if (user == null) { MessageBox.Show("There is no existing account for this email. Create an account."); txt_LoginPassword.Clear(); txtLoginEmail.Clear(); } else { // add password encryption here later if (user.Password == txt_LoginPassword.Text) { CurrentUser = user; this.Hide(); Form2 form2 = new Form2(CurrentUser); form2.ShowDialog(); this.Close(); /* Form2 form2 = new Form2(CurrentUser); * form2.ShowDialog();*/ } else { MessageBox.Show($"You've entered the wrong password for {user.FirstName} {user.LastName}.Try again."); txt_LoginPassword.Clear(); txtLoginEmail.Clear(); } } } }
public Form3(User currentUser) { InitializeComponent(); CurrentUser = currentUser; lbl_likedSong.Hide(); var context = new MusicAppContext(); var existingPlaylists = context.Playlists .Where(p => p.UserId == CurrentUser.UserId); if (existingPlaylists != null) { var usersPlaylists = existingPlaylists.ToList(); lb_UserPlaylists.DataSource = usersPlaylists; //lb_UserPlaylists.DisplayMember = "Name"; //lb_UserPlaylists.ValueMember = "Id"; } else { lb_UserPlaylists.Text = "You have no playlists. Create one!"; } }
private void lb_UserPlaylists_SelectedIndexChanged(object sender, EventArgs e) { Playlist chosenPlaylist = (Playlist)lb_UserPlaylists.SelectedItem; var context = new MusicAppContext(); var playlistSongs = context.PlaylistSongs .Where(p => p.PlaylistId == chosenPlaylist.PlaylistId) .Include("Song").ToList(); List <Song> songs = new List <Song>(); foreach (var row in playlistSongs) { songs.Add(context.Songs.FirstOrDefault(s => s.SongId == row.SongId)); context.SaveChanges(); } /* foreach (var item in playlistSongs) * { * MessageBox.Show(item.Song.ToString()); * }*/ //stops first song being automatically selected and playing lb_PlaylistSongs.SelectedIndexChanged -= lb_PlaylistSongs_SelectedIndexChanged; lb_PlaylistSongs.DataSource = null; lb_PlaylistSongs.DataSource = songs; lb_PlaylistSongs.SelectedIndex = -1; // This optional line keeps the first item from being selected. lb_PlaylistSongs.SelectedIndexChanged += lb_PlaylistSongs_SelectedIndexChanged; //lb_PlaylistSongs.DisplayMember = ""; }
private void btnLogin_Click(object sender, EventArgs e) { string email = txtUserMail.Text; string paswoord = txtUserPW.Text; using (var ctx = new MusicAppContext()) { bool exists = ctx.Users.Any(u => u.Email == email); if (exists) { var user = ctx.Users.Select(u => u).Where(u => u.Email == email); if (user.Any(u => u.Password == paswoord)) { using (FormMain formMain = new FormMain()) { if (formMain.ShowDialog() == DialogResult.OK) { formMain.Close(); } } } } } }
private void btn_SavePlaylist_Click(object sender, EventArgs e) { Playlist newPlaylist = new Playlist() { UserId = CurrentUser.UserId, Name = txt_NewPlaylistName.Text, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; var context = new MusicAppContext(); context.Playlists.Add(newPlaylist); foreach (var song in AllChosenSongs) { PlaylistSong newPlaylistSong = new PlaylistSong() { PlaylistId = newPlaylist.PlaylistId, SongId = song.SongId }; context.PlaylistSongs.Add(newPlaylistSong); context.SaveChanges(); MessageBox.Show($"{newPlaylist.Name} is saved!"); this.Close(); } }
private void btn_AddArtist_Click(object sender, EventArgs e) { string newArtist = txt_AddArtist.Text; var context = new MusicAppContext(); if (context.Artists.FirstOrDefault(a => a.Name == txt_AddArtist.Text) != null) { MessageBox.Show("This artist already exists"); txt_AddArtist.Clear(); } else { DateTime currentDate = DateTime.Now; Artist artist = new Artist() { Name = txt_AddArtist.Text, CreatedAt = currentDate, UpdatedAt = currentDate }; context.Artists.Add(artist); context.SaveChanges(); var artistCollection = context.Artists.Select(a => new { Name = a.Name, Id = a.ArtistId }).ToList(); cb_Artists.DataSource = null; cb_Artists.DataSource = artistCollection; cb_Artists.DisplayMember = "Name"; cb_Artists.ValueMember = "Id"; txt_AddArtist.Clear(); } }
private void btn_like_Click(object sender, EventArgs e) { var context = new MusicAppContext(); Song song = (Song)lb_PlaylistSongs.SelectedItem; Interaction existingInteraction = context.Interactions.FirstOrDefault(i => i.UserId == CurrentUser.UserId && i.SongId == song.SongId); existingInteraction.Liked = 1; MessageBox.Show("Song liked"); context.SaveChanges(); }
private void cbPlaylists_SelectedIndexChanged(object sender, EventArgs e) { Playlist selected = cbPlaylists.SelectedItem as Playlist; using (var ctx = new MusicAppContext()) { List <Song> playlist = selected.Songs.ToList(); lbPLSongs.ValueMember = "SongId"; lbPLSongs.DisplayMember = "Title"; lbPLSongs.DataSource = playlist; } }
public FormSong() { InitializeComponent(); using (var ctx = new MusicAppContext()) { List <Album> albums = ctx.Albums.ToList(); cbAlbums.ValueMember = "AlbumId"; cbAlbums.DisplayMember = "Name"; cbAlbums.DataSource = albums; } }
public FormAlbum() { InitializeComponent(); using (var ctx = new MusicAppContext()) { List <Artist> artists = ctx.Artists.ToList(); cbArtists.ValueMember = "ArtistId"; cbArtists.DisplayMember = "Name"; cbArtists.DataSource = artists; } }
public FormPlay() { InitializeComponent(); using (var ctx = new MusicAppContext()) { List <Playlist> playlists = ctx.Playlists.ToList(); cbPlaylists.ValueMember = "PlaylistId"; cbPlaylists.DisplayMember = "Name"; cbPlaylists.DataSource = playlists; } }
private void btnAddArtist_Click(object sender, EventArgs e) { using (var ctx = new MusicAppContext()) { ctx.Artists.Add(new Artist() { Name = txtArtist.Text, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }); ctx.SaveChanges(); } Close(); }
private void btnAanmaken_Click(object sender, EventArgs e) { using (var ctx = new MusicAppContext()) { ctx.Users.Add(new User() { FirstName = txtVoornaam.Text, LastName = txtAchternaam.Text, Email = txtEmail.Text, Password = txtPaswoord.Text }); ctx.SaveChanges(); } MessageBox.Show("Uw account werd met succes aangemaakt!"); Close(); }
private void cbAlbums_SelectedIndexChanged(object sender, EventArgs e) { Album selected = cbAlbums.SelectedItem as Album; using (var ctx = new MusicAppContext()) { List <Song> songlist = selected.Songs.ToList(); lbSonglist.ValueMember = "SongId"; lbSonglist.DisplayMember = "Title"; lbSonglist.DataSource = songlist; foreach (Song item in songlist) { lbSonglist.Items.Add(item.ToString()); } } }
private void btnAddAlbum_Click(object sender, EventArgs e) { Artist selected = cbArtists.SelectedItem as Artist; using (var ctx = new MusicAppContext()) { Album album = new Album() { Name = txtNameAlbum.Text, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; ctx.Albums.Add(album); ctx.SaveChanges(); } Close(); }
private void btnAddSong_Click(object sender, EventArgs e) { Album selected = cbAlbums.SelectedItem as Album; using (var ctx = new MusicAppContext()) { Song song = new Song() { Title = txtSong.Text, Length = (int)nudLengte.Value, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; ctx.Songs.Add(song); ctx.SaveChanges(); } Close(); }
private void chk_playlistYes_CheckedChanged(object sender, EventArgs e) { if (chk_playlistYes.Checked) { cb_ChoosePlaylist.Show(); lbl_choosePlaylist.Show(); var context = new MusicAppContext(); List <Playlist> usersPlaylists = context.Playlists.Where(p => p.UserId == CurrentUser.UserId).ToList(); cb_ChoosePlaylist.DataSource = usersPlaylists; //cb_ChoosePlaylist.ValueMember = "PlaylistId"; } else { cb_ChoosePlaylist.Hide(); lbl_choosePlaylist.Hide(); } }
private void lb_PlaylistSongs_SelectedIndexChanged(object sender, EventArgs e) { Song song = (Song)lb_PlaylistSongs.SelectedItem; var context = new MusicAppContext(); //checking all interactions in the interaction table - how to just check the users? Interaction existingInteraction = context.Interactions.FirstOrDefault(i => i.UserId == CurrentUser.UserId && i.SongId == song.SongId); if (existingInteraction == null) { Interaction interaction = new Interaction() { UserId = CurrentUser.UserId, SongId = song.SongId, Liked = 0, PlayCount = 1, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; context.Interactions.Add(interaction); //existingInteraction = interaction; //CurrentUser.Interactions.Add(interaction); - error " not set to an instance of an object) context.SaveChanges(); MessageBox.Show($"{song.Title} is now playing.... \n You've played it {interaction.PlayCount} times."); } else { if (existingInteraction.Liked == 1) { btn_like.Enabled = false; lbl_likedSong.Show(); } else { btn_like.Enabled = true; lbl_likedSong.Hide(); } existingInteraction.PlayCount++; existingInteraction.UpdatedAt = DateTime.Now; context.SaveChanges(); MessageBox.Show($"{song.Title} is now playing.... \n You've played it {existingInteraction.PlayCount} times."); } }
public Form4(User currentUser) { InitializeComponent(); CurrentUser = currentUser; var context = new MusicAppContext(); var albumCollection = context.Albums .Include("Artist") /* .Select(a => new * { * NameAndArtist = a.Name + " " + "by " + a.Artist.Name, * Id = a.AlbumId * })*/ .ToList(); cb_ChooseAlbum.DataSource = albumCollection; cb_ChooseAlbum.DisplayMember = "Name"; //cb_ChooseAlbum.ValueMember = "Id"; }
private void cb_ChooseAlbum_SelectedIndexChanged(object sender, EventArgs e) { // int selectedAlbum = Convert.ToInt32(cb_ChooseAlbum.SelectedValue); int selectedAlbum = ((Album)cb_ChooseAlbum.SelectedItem).AlbumId; var context = new MusicAppContext(); var songsOnAlbum = context.Songs .Where(s => s.AlbumId == selectedAlbum) /*.Select(s => new * { * Id = s.SongId, * Title = s.Title, * })*/ .ToList(); lb_ChooseSong.DataSource = songsOnAlbum; lb_ChooseSong.DisplayMember = "Title"; //lb_ChooseSong.ValueMember = "SongId"; }
private void btnSignUp_Click(object sender, EventArgs e) { using (Form2 form2 = new Form2()) { switch (form2.ShowDialog()) { case DialogResult.OK: using (MusicAppContext data = new MusicAppContext()) { data.User.Add(new User() { FirstName = form2.FirstName, LastName = form2.LastName, Email = form2.Email, Password = form2.Password }); data.SaveChanges(); } break; } } }
private void btnMakePL_Click(object sender, EventArgs e) { using (var ctx = new MusicAppContext()) { Playlist playlist = new Playlist() { Name = txtNamePL.Text, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, }; ctx.Playlists.Add(playlist); foreach (Song item in lbPlaylist.Items) { playlist.Songs.Add(item); } ctx.SaveChanges(); } Close(); }
private void btn_createAccount_Click(object sender, EventArgs e) { string firstName = txt_FirstName.Text; string lastName = txt_LastName.Text; string email = txt_createEmail.Text; string password = txt_createPassword.Text; var context = new MusicAppContext(); if (context.Users.FirstOrDefault(u => u.Email == txt_createEmail.Text) != null) { MessageBox.Show("This user already has an account. You can log in."); txt_FirstName.Clear(); txt_LastName.Clear(); txt_createEmail.Clear(); txt_createPassword.Clear(); } else { //using (MusicAppContext context = new MusicAppContext()) //{ context.Users.Add(new User() { FirstName = firstName, LastName = lastName, Email = email, Password = password }); context.SaveChanges(); MessageBox.Show($"You have successfully created an account for {firstName} {lastName}. Now you can log in."); txt_FirstName.Clear(); txt_LastName.Clear(); txt_createEmail.Clear(); txt_createPassword.Clear(); //} } }
private void btn_AddAlbum_Click(object sender, EventArgs e) { var context = new MusicAppContext(); int selectedId = Convert.ToInt32(cb_Artists.SelectedValue); if (context.Albums.FirstOrDefault(a => a.Name == txt_AddAlbum.Text && a.ArtistId == selectedId) != null) { MessageBox.Show($"This album already exists."); txt_AddAlbum.Clear(); } else { DateTime currentDate = DateTime.Now; Album album = new Album() { Name = txt_AddAlbum.Text, ArtistId = selectedId, CreatedAt = currentDate, UpdatedAt = currentDate }; context.Albums.Add(album); context.SaveChanges(); var albumCollection = context.Albums.Include("Artist").Select(a => new { NameAndArtist = a.Name + " " + "by " + a.Artist.Name, Id = a.AlbumId }).ToList(); cb_Albums.DataSource = null; cb_Albums.DataSource = albumCollection; cb_Albums.DisplayMember = "NameAndArtist"; cb_Albums.ValueMember = "Id"; txt_AddAlbum.Clear(); } }
private void btn_AddSong_Click(object sender, EventArgs e) { var context = new MusicAppContext(); int selectedId = Convert.ToInt32(cb_Albums.SelectedValue); if (context.Songs.FirstOrDefault(s => s.Title == txt_AddSong.Text && s.AlbumId == selectedId) != null) { MessageBox.Show($"This song already exists in the album."); txt_AddSong.Clear(); } else { Album album = context.Albums .Where(a => a.AlbumId == selectedId) .FirstOrDefault(); Song song = new Song() { AlbumId = selectedId, ArtistId = album.ArtistId, Title = txt_AddSong.Text, Length = 2.5, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; context.Songs.Add(song); context.SaveChanges(); if (chk_playlistYes.Checked) { var ExistingPlaylists = context.Playlists.Where(p => p.UserId == CurrentUser.UserId); if (ExistingPlaylists != null) { /*var usersPlaylists = ExistingPlaylists * .Select(p => new * { * Name = p.Name, * Details = p.Name + " " + "Last updated: " + p.UpdatedAt, * Id = p.PlaylistId * }).ToList(); * * cb_ChoosePlaylist.DataSource = usersPlaylists; * cb_ChoosePlaylist.DisplayMember = "Name"; * cb_ChoosePlaylist.ValueMember = "Id";*/ Playlist selectedPlaylist = (Playlist)cb_ChoosePlaylist.SelectedItem; PlaylistSong newSongForPlaylist = new PlaylistSong() { PlaylistId = selectedPlaylist.PlaylistId, SongId = song.SongId }; context.PlaylistSongs.Add(newSongForPlaylist); context.SaveChanges(); Playlist playList = context.Playlists.FirstOrDefault(p => p.PlaylistId == selectedPlaylist.PlaylistId); var playListSongs = context.PlaylistSongs.Where(ps => ps.PlaylistId == playList.PlaylistId).ToList(); int NumberOfSongs = playListSongs.Count; MessageBox.Show($"{song.Title} has been added to the playlist '{playList.Name}'.\n This playlist now has {NumberOfSongs} songs."); Playlist playlist = context.Playlists.FirstOrDefault(p => p.PlaylistId == selectedPlaylist.PlaylistId); playlist.UpdatedAt = DateTime.Now; context.SaveChanges(); } else { cb_ChoosePlaylist.Text = "You have no playlists"; } } } }