Ejemplo n.º 1
0
        public static void Delete(Guitar guitar)
        {
            using (GuitarContext context = new GuitarContext())
            {
                context.Database.Log = Console.WriteLine;

                context.Entry(guitar).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public static Guitar Update(Guitar guitar)
        {
            using (var context = new GuitarContext())
            {
                context.Database.Log = Console.WriteLine;

                context.Entry(guitar).State = EntityState.Modified;
                context.SaveChanges();

                return(guitar);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a guitar to the database.
        /// Returns guitar with <see cref="GetGuitars.GuitarId"/>
        /// property(identity column) populated.
        /// </summary>
        /// <param name="guitar">The guitar to be added</param>
        public static Guitar Add(Guitar guitar)
        {
            using (var guitarContext = new GuitarContext())
            {
                guitarContext.Database.Log = Console.WriteLine;

                guitarContext.Guitars.Add(guitar);
                guitarContext.SaveChanges();

                return(guitar);
            }
        }
Ejemplo n.º 4
0
        public static void Delete(int id)
        {
            using (GuitarContext context = new GuitarContext())
            {
                Guitar guitarToDelete = (from guitar in context.Guitars
                                         where guitar.GuitarId == id
                                         select guitar).Single();


                context.Entry(guitarToDelete).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        private void AddGuitarBtn_Click(object sender, EventArgs e)
        {
            // Create Guitar object to add
            Guitar guitar = new Guitar
            {
                Brand      = BrandTxtBox.Text,
                GuitarType = GuitarTypeTxtBox.Text,
                Color      = ColorTxtBox.Text,
                Value      = double.Parse(ValueTxtBox.Text)
            };
            DialogResult dialog = MessageBox.Show("Is everything correct?",
                                                  "Guitar",
                                                  MessageBoxButtons.YesNo,
                                                  MessageBoxIcon.Hand,
                                                  MessageBoxDefaultButton.Button2);

            if (dialog == DialogResult.Yes)
            {
                GuitarDb.Add(guitar);
                MessageBox.Show("Guitar Added!");
            }
        }