예제 #1
0
        /// <summary>
        /// Decrements account sum and calculates bonus with injected strategy.
        /// </summary>
        /// <param name="sum">
        /// Sum to withdraw.
        /// </param>
        /// <param name="bonusLogic">
        /// Bonus calculation strategy.
        /// </param>
        public override void WithDraw(decimal sum, IBonusLogic bonusLogic)
        {
            if (bonusLogic == null)
            {
                throw new ArgumentException(message: "Bonus score logic is null");
            }

            if (sum <= 0)
            {
                throw new ArgumentException(message: "Sum to withdraw cannot be less or equil zero");
            }

            if (this.AccountSum < sum)
            {
                throw new InvalidOperationException(message: "This type of account does not support credit");
            }

            this.AccountSum -= sum;
            int bonusSubtraction = bonusLogic.WithdrawBonusSubtraction(sum, this.WithdrawCostSubtraction, this.BalanceCost);

            if (this.BonusScore > bonusSubtraction)
            {
                this.BonusScore -= bonusSubtraction;
            }
            else
            {
                this.BonusScore = 0;
            }
        }
예제 #2
0
        /// <summary>
        /// Increments account sum and calculates bonus with injected strategy.
        /// </summary>
        /// <param name="sum">
        /// Sum to put.
        /// </param>
        /// <param name="bonusLogic">
        /// Bonus calculation strategy.
        /// </param>
        public override void Put(decimal sum, IBonusLogic bonusLogic)
        {
            if (bonusLogic == null)
            {
                throw new ArgumentException(message: "Bonus score logic is null");
            }

            if (sum <= 0)
            {
                throw new ArgumentException(message: "Sum to put cannot be less or equil zero");
            }

            this.AccountSum += sum;
            this.BonusScore += bonusLogic.PutBonus(sum, this.PutCost, this.BalanceCost);
        }
예제 #3
0
 /// <summary>
 /// Method decrements accountSum for account.
 /// </summary>
 /// <param name="sum">
 /// Sum to withdraw.
 /// </param>
 /// <param name="bonusLogic">
 /// Bonus calculation strategy.
 /// </param>
 public abstract void WithDraw(decimal sum, IBonusLogic bonusLogic);
예제 #4
0
 /// <summary>
 /// Method increments accountSum for account.
 /// </summary>
 /// <param name="sum">
 /// Some to put.
 /// </param>
 /// <param name="bonusLogic">
 /// Bonus calculation strategy.
 /// </param>
 public abstract void Put(decimal sum, IBonusLogic bonusLogic);
 /// <summary>
 /// Initializes a new instance of the <see cref="AccountService"/> class.
 /// </summary>
 /// <param name="repository">
 /// Constructor injected dependancy that defines repository for bank accounts.
 /// </param>
 /// <param name="bonusLogic">
 /// Constructor injected dependancy that defines bonus logic.
 /// </param>
 public AccountService(IRepository <AccountDTO> repository, IBonusLogic bonusLogic)
 {
     this.repository = repository;
     this.bonusLogic = bonusLogic;
 }