public static int AddArtist(string artistName) { var artist = new CDCatalogEF.Artist(); try { artist.ArtistName = artistName; using (var db = new CDCatalogEntities()) { db.Artists.Add(artist); //faults here var resultCount = db.SaveChanges(); } } catch (Exception ex) { // Define a new top-level error message. string str = "Adding the Artist by Name failed. " + ex.Message; // Pop-up a messagebox with the message MessageBox.Show(str); } var artistId = artist.ArtistID; return artistId; }
private void AddArtistButton_Click(object sender, EventArgs e) { // In the AddAlbum form, the user clicked the AddArtist button // this opens the AddArtist pop-up DialogResult dr = new DialogResult(); AddArtistWF frm = new AddArtistWF(); // When the AddArtist pop-is closed, determie why. dr = frm.ShowDialog(); if (dr == DialogResult.OK) { // Acknowledge the change MessageBox.Show("AddArtist: User clicked OK button"); // Get the newly created genre object CDCatalogEF.Artist artist = (CDCatalogEF.Artist) this.addArtistButton.Tag; // Refresh the combo box with the artist that was just added this.artistTableAdapter.Fill(this.cDCatalogDataSet2.Artist); int index = artistComboBox.FindStringExact(artist.ArtistName); //Exception here artistComboBox.SelectedIndex = index; this.Close(); } else if (dr == DialogResult.Cancel) { MessageBox.Show("AddArtist: User clicked Cancel button"); this.Close(); } }
public static int AddArtist(string artistName) { var artist = new CDCatalogEF.Artist(); try { artist.ArtistName = artistName; using (var db = new CDCatalogEntities()) { db.Artists.Add(artist); //faults here var resultCount = db.SaveChanges(); } } catch (Exception ex) { // Define a new top-level error message. string str = "Adding the Artist by Name failed. " + ex.Message; // Pop-up a messagebox with the message MessageBox.Show(str); } var artistId = artist.ArtistID; return(artistId); }
public static CDCatalogEF.Artist GetArtistById(int artistId) { var artist = new CDCatalogEF.Artist(); try { using (var db = new CDCatalogEntities()) { artist = db.Artists.Where(a => a.ArtistID == artistId).FirstOrDefault(); } } catch (Exception ex) { // Define a new top-level error message. string str = "Getting the Artist failed. " + ex.Message; // Pop-up a messagebox with the message MessageBox.Show(str); } return(artist); }
public static bool DeleteAtristById(int artistId) { try { using (var db = new CDCatalogEntities()) { // Find one artist CDCatalogEF.Artist artist = db.Artists.Where(n => n.Equals(artistId)).Single(); db.Artists.Remove(artist); return(true); //if there is an exception, this won't run } } catch (Exception ex) { // Define a new top-level error message. string str = "Deleting the Artist failed. " + ex.Message; // Pop-up a messagebox with the message MessageBox.Show(str); } return(false); }
public static CDCatalogEF.Artist GetArtistById(int artistId) { var artist = new CDCatalogEF.Artist(); try { using (var db = new CDCatalogEntities()) { artist = db.Artists.Where(a => a.ArtistID == artistId).FirstOrDefault(); } } catch (Exception ex) { // Define a new top-level error message. string str = "Getting the Artist failed. " + ex.Message; // Pop-up a messagebox with the message MessageBox.Show(str); } return artist; }