private void addItemButton_Click(object sender, EventArgs e) { aProduct=new Product(); aProduct.ProductId = productIdTextBox.Text; aProduct.Quantity = Convert.ToInt32(quantityTextBox.Text); MessageBox.Show( aShop.AddItem(aProduct.ProductId,aProduct.Quantity)); }
private bool HasThisProductIdExist(string prouctId) { foreach (Product product in productList) { if (product.ProductId== prouctId) { aProduct = product; return true; } } return false; }
public string AddItem(string productId, int quantity) { string msg = ""; if (HasThisProductIdExist(productId)) { aProduct.Quantity += quantity; msg = "Already exist! Quantity added"; } else { aProduct = new Product(); aProduct.ProductId = productId; aProduct.Quantity = quantity; productList.Add(aProduct); msg="Item added"; } return msg; }