private void button14_Click(object sender, EventArgs e) { if (SectionNumber == 1) { int id = int.Parse(textBox1.Text); var pastry = pastryController.GetPastryById(id); pastry.Category = textBox5.Text; pastry.Name = textBox2.Text; pastry.Price = decimal.Parse(textBox3.Text); pastry.Quantity = int.Parse(textBox4.Text); pastryController.Update(pastry); } if (SectionNumber == 2) { int id = int.Parse(textBox1.Text); var fruitsAndVegetable = fruitAndVegetableController.GetFruitOrVegetableById(id); fruitsAndVegetable.Category = textBox5.Text; fruitsAndVegetable.Name = textBox2.Text; fruitsAndVegetable.Price = decimal.Parse(textBox3.Text); fruitsAndVegetable.Quantity = int.Parse(textBox4.Text); fruitAndVegetableController.Update(fruitsAndVegetable); } if (SectionNumber == 3) { int id = int.Parse(textBox1.Text); var nut = nutController.GetNutById(id); nut.Category = textBox5.Text; nut.Name = textBox2.Text; nut.Price = decimal.Parse(textBox3.Text); nut.Quantity = int.Parse(textBox4.Text); nutController.Update(nut); } if (SectionNumber == 4) { int id = int.Parse(textBox1.Text); var drink = drinkController.GetDrinkById(id); drink.Category = textBox5.Text; drink.Name = textBox2.Text; drink.Price = decimal.Parse(textBox3.Text); drink.Quantity = int.Parse(textBox4.Text); drinkController.Update(drink); } MessageBox.Show("The product was updated successfully!"); }
private void UpdateNut() { Console.Write("Enter ID: "); int id = int.Parse(Console.ReadLine()); var nut = nutController.GetNutById(id); if (nut != null) { Console.WriteLine($"{nut.Id} {nut.Category} {nut.Name} {nut.Price}lv/kg {nut.Quantity}kg."); var elements = ReadElements(); nut.Category = elements[0]; nut.Name = elements[1]; nut.Price = decimal.Parse(elements[2]); nut.Quantity = int.Parse(elements[3]); nutController.Update(nut); Console.WriteLine("The product was updated successfully!"); } else { Console.WriteLine("The product was not found"); } }