private void RemoveButton_Click(object sender, EventArgs e) { int ID; if (int.TryParse(ProductID.Text, out ID)) { if (_PHPRepo.VerifyProductID(ID)) { _PHPRepo.GetProductbyId(ID); Product _Product = _PHPRepo.GetProductbyId(ID); _PHPRepo.deleteProduct(_Product); MessageBox.Show("Product has been deleted ", "Sucessful", MessageBoxButtons.OK, MessageBoxIcon.None); StockList.Items.Clear(); List <Product> _NewList = _PHPRepo.GetProducts(); foreach (Product p in _NewList) { string[] row = { p.ProductId.ToString(), p.Product_Name.ToString(), p.Price.ToString(), p.Stock_Level.ToString() }; var listViewItem = new ListViewItem(row); StockList.Items.Add(listViewItem); } ; ProductID.Clear(); } else { MessageBox.Show("Could not find item: " + ID); } } else { MessageBox.Show("Please enter a valid ID"); } }
public void DeleteProduct() { Console.WriteLine("Select product to delete : "); ListProducts(); int id = int.Parse(Console.ReadLine()); var productToDelete = _phpRepo.GetProductbyId(id); _phpRepo.deleteProduct(productToDelete); }