private void button3_Click(object sender, EventArgs e) { var db = new ChemistryContext(); if (dataGridView1.SelectedRows.Count > 0) { int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } Recipe recipe = db.Recipes.Find(id); RecipeForm recForm = new RecipeForm(); recForm.textBox1.Text = recipe.Name; recForm.textBox2.Text = recipe.Description; DialogResult result = recForm.ShowDialog(this); recipe.Name = recForm.textBox1.Text; recipe.Description = recForm.textBox2.Text; db.Entry(recipe).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("Updated"); } }//Dimash
//ADd private void button4_Click(object sender, EventArgs e) { var db = new ChemistryContext(); RecipeForm recForm = new RecipeForm(); DialogResult result = recForm.ShowDialog(this); //if (result == DialogResult.Cancel) // return; Recipe recipe = new Recipe(); recipe.Name = recForm.textBox1.Text; recipe.Description = recForm.textBox2.Text; db.Recipes.Add(recipe); db.SaveChanges(); MessageBox.Show("New recipe added"); }