Exemple #1
0
        /// <summary>
        /// Withdraw sum from account
        /// </summary>
        /// <param name="sum"></param>
        public void Withdraw(decimal sum, IBonus bonusLogic)
        {
            if (sum < 0)
            {
                throw new ArgumentException("Sum cannot be negative");
            }

            if (IsActive)
            {
                if (Balance >= sum)
                {
                    Balance -= sum;
                    Bonus    = bonusLogic.Withdraw(sum, Type) < Bonus ? Bonus - bonusLogic.Withdraw(sum, Type) : 0;
                }
                else
                {
                    throw new Exception("Not enough money");
                }
            }
            else
            {
                throw new Exception("Account closed");
            }
        }