Example #1
0
        /// <summary>
        /// General action: increment (action=1) or decrement (action=-1).
        /// </summary>
        /// <param name="item"></param>
        /// <param name="price"></param>
        /// <param name="itemInCartPanel"></param>
        /// <param name="action"></param>
        private void UpdateUnits(Item item, Price price, FlowLayoutPanel itemInCartPanel, int action)
        {
            if (action == 1)
            {
                _cartManager.IncrementItemUnitToCart(_cart, item);
            }
            else
            {
                _cartManager.DecrementItemUnitToCart(_cart, item);
            }
            int   amount         = _cartManager.GetCartItemAmount(_cart, item);
            Label lbl_amountUnit = GetAmountLabelFromPanel(itemInCartPanel);

            lbl_amountUnit.Text = $"{amount}";
            Label lbl_priceUnit = GetPriceUnitLabelFromPanel(itemInCartPanel);

            if (price == null)
            {
                lbl_priceUnit.Text = $"? {Constants.Currency}";
                Label lbl_priceTotal = GetPriceTotalLabelFromPanel(itemInCartPanel);
                lbl_priceTotal.Text = $"? {Constants.Currency}";
            }
            else
            {
                lbl_priceUnit.Text = $"{price.PriceValue} {Constants.Currency}";
                Label lbl_priceTotal = GetPriceTotalLabelFromPanel(itemInCartPanel);
                lbl_priceTotal.Text = $"{price.PriceValue * amount} {Constants.Currency}";
            }
            if (_cartManager.GetCartItemAmount(_cart, item) == 0)
            {
                MessageBox.Show("Decremented to zero.");
                RemoveItemFromCart(item, itemInCartPanel);
            }

            UpdateCartControllers();
        }