Пример #1
0
        public static CDCatalogEF.Genre AddGenre(string genreName)
        {
            if (genreName == null)
            {
                // Define a new top-level error message.
                string str = "You did not enter a Genre Name.  Cancel this operation?";

                // Pop-up a messagebox with the message
                MessageBox.Show(str);
                return(null);
            }
            var genre = new CDCatalogEF.Genre();

            try
            {
                genre.GenreName = genreName;

                using (var db = new CDCatalogEntities())
                {
                    db.Genres.Add(genre);
                    var resultCount = db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                // Define a new top-level error message.
                string str = "Adding the Genre by Name failed. " + ex.Message;

                // Pop-up a messagebox with the message
                MessageBox.Show(str);
            }
            return(genre);
        }
Пример #2
0
        private void AddGenreButton_Click(object sender, EventArgs e)
        {
            // In the AddAlbum form, the user clicked the AddGenre button
            // this opens the AddGenre pop-up
            DialogResult dr  = new DialogResult();
            AddGenreWF   frm = new AddGenreWF();

            // When the AddGenre pop-is closed, determine why.
            dr = frm.ShowDialog();
            if (dr == DialogResult.OK)
            {
                // MessageBox.Show("User clicked OK button");
                // Get the newly created genre object
                CDCatalogEF.Genre genre = (Genre)this.addGenreButton.Tag;

                // Show updated list in the combo box
                this.genreTableAdapter.Fill(this.cDCatalogDataSet3.Genre);

                //Show the selected item
                this.genreComboBox.SelectedIndex = this.genreComboBox.FindString(genre.GenreName);

                this.Close();
            }
            else if (dr == DialogResult.Cancel)
            {
                MessageBox.Show("AddGenre: User clicked Cancel button");
                this.Close();
            }
        }
Пример #3
0
        public static bool DeleteGenreById(int genreId)
        {
            try
            {
                using (var db = new CDCatalogEntities())
                {
                    CDCatalogEF.Genre genre = db.Genres.Where(n => n.Equals(genreId)).Single();
                    db.Genres.Remove(genre);
                    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 Genre failed. " + ex.Message;

                // Pop-up a messagebox with the message
                MessageBox.Show(str);
            }
            return(false);
        }
Пример #4
0
        public static CDCatalogEF.Genre GetGenreById(int genreId)
        {
            var genre = new CDCatalogEF.Genre();

            try
            {
                using (var db = new CDCatalogEntities())
                {
                    genre = db.Genres.Where(a => a.GenreID == genreId).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                // Define a new top-level error message.
                string str = "Getting the Genre failed. " + ex.Message;

                // Pop-up a messagebox with the message
                MessageBox.Show(str);
            }
            return(genre);
        }