public void Add(ItemSales sale) { bool isInList = false; foreach (ItemSales s in Sales) { if (sale.item == s.item) { s.Quantity++; isInList = true; } } if (!isInList) { Sales.Add(sale); } }
public void Remove(ItemSales sale) { bool isInList = true; foreach (ItemSales s in Sales) { if (sale.item == s.item) { s.Quantity--; isInList = false; } } if (!isInList) { Sales.Remove(sale); } }
// Adds the item and the quantity of the item selected to the cart. protected void ListViewItem_ItemCommand(object sender, ListViewCommandEventArgs e) { if (e.CommandName == "AddToCart") { ItemSales sale = new ItemSales(); try { sale.item = ((Label)e.Item.FindControl("lblItemName")).Text; sale.Price = Convert.ToDouble(((Label)e.Item.FindControl("lblItemPrice")).Text); sale.Quantity = Convert.ToInt32(((TextBox)e.Item.FindControl("txtItemQuantity")).Text); listOfSales.Add(sale); RefreshCart(); pnlCheckOut.Visible = true; ((TextBox)e.Item.FindControl("txtItemQuantity")).Text = ""; } catch (Exception ex) { lblError.Text = "Something went wrong: " + ex.Message; } } }