public static void Delete(Guitar guitar) { using (GuitarContext context = new GuitarContext()) { context.Database.Log = Console.WriteLine; context.Entry(guitar).State = EntityState.Deleted; context.SaveChanges(); } }
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); } }
/// <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); } }
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(); } }
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!"); } }