Exemplo n.º 1
0
        public bool TryAddLineItems(Stock s, int amount)
        {
            bool hasKey = LineItemUnits.ContainsKey(s.Matter);

            if ((hasKey && LineItemUnits[s.Matter] + amount > -1) || (!hasKey && amount > -1))
            {
                if (hasKey)
                {
                    LineItemUnits[s.Matter] += amount;
                }
                else
                {
                    LineItemUnits[s.Matter] = amount;
                }

                MatterCost += s.ListPrice * amount;

                RecalcVolumeMassShipping();

                //validate
                if (amount > 0)
                {
                    if (TotalVolume > Via.MaximumVolume() || TotalMass > Via.MaximumMass())
                    {
                        TryAddLineItems(s, -amount);
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }