// CartItemBox private void OnAnyButtonClick_CartItemBox(object sender, EventArgs e) { Button button = (Button)sender; ProductAmount pe = (ProductAmount)button.Tag; if (button.Name == "QuantityAddButton") { cart.Add(pe.Product); RefreshTotalCost(); var c = GetCartItemBox(); if (cart.TryGetRebate(pe.SerialNumber, out DiscountAmount de)) { c.SetDiscountInfo(de); } } else if (button.Name == "QuantitySubtractButton") { cart.Remove(pe.Product); RefreshTotalCost(); var c = GetCartItemBox(); if (c.HasDiscountInfo) { cart.TryGetRebate(pe.SerialNumber, out DiscountAmount de); c.SetDiscountInfo(de); } } else if (button.Name == "RemoveButton") { cart.RemoveAll(pe.Product); RefreshTotalCost(); } // lokal metod för att undvika kod-duplicering: CartItemBox GetCartItemBox() => (CartItemBox)(button.Parent.Parent.Parent.Parent.Parent.Parent); }
public bool TryGet(int serialNumber, out ProductAmount productAmount) => cart.cart.TryGetValue(serialNumber, out productAmount);
public void Add(ProductAmount productEntry) => Add(productEntry.Product, productEntry.Amount);