private void addToCart(Article article) { //Checks if the selected articles quantity is more than 0 //if true then try to add the article to the shopping cart if (int.Parse(article.getAttributeValue("quantity")) > 0) { var inventoryQTY = int.Parse(article.getAttributeValue("quantity")); //Checks if the article already exists in the shopping cart, //if true then increment its quantity by 1 if (cartList.articleExists(article.getAttributeValue("id"))) { var index = cartList.findArticleIndex(article.getAttributeValue("id")); var qty = cartList.articleList[index].getAttributeValue("quantity"); cartList.articleList[index].setAttributeValue("quantity", (int.Parse(qty) + 1).ToString()); } //else add the article to the shopping cart with a quantity of 1 else { cartList.addArticle(article); cartList.articleList.Last().setAttributeValue("quantity", "1"); } article.setAttributeValue("quantity", (inventoryQTY - 1).ToString()); var inventoryIndex = inventoryList.findArticleIndex(article.getAttributeValue("id")); inventoryList.articleList[inventoryIndex].setAttributeValue("quantity", (inventoryQTY - 1).ToString()); } else { MessageBox.Show("There is no more stock of that item."); } }