예제 #1
0
 private void SaveChanges(BankAccount account)
 {
     try
     {
         _accountStorage.UpdateAccount(account.ToAccountDal());
     }
     catch (StorageException e)
     {
         throw new BankManagerException("An error occurred while working with the repository.", e);
     }
 }
        /// <summary>
        /// Refills a bank account with the <paramref name="id"/> by the <paramref name="amount"/>.
        /// </summary>
        /// <param name="id">The bank account id.</param>
        /// <param name="amount">The amount to refill.</param>
        /// <exception cref="ArgumentException">
        /// Thrown when <paramref name="id"/> or/and <paramref name="amount"/> less than 0.
        /// </exception>
        /// <exception cref="BankServiceException">
        /// Thrown when the bank account with the <paramref name="id"/> not found,
        /// something wrong with updating in the storage or insufficient founds to refill.
        /// </exception>
        public void Refill(int id, decimal amount)
        {
            if (id < 0)
            {
                throw new ArgumentException("The id must be greater than or equal to 0.", nameof(id));
            }

            if (amount < 0)
            {
                throw new ArgumentException("The amount must be greater than or equal to 0.", nameof(amount));
            }

            UpdateList();

            BankAccount bankAccount = _bankAccounts.Find(x => x.ID == id);

            if (ReferenceEquals(bankAccount, null))
            {
                throw new BankServiceException("No such bank account.");
            }

            AccountTypeFeatures features = new AccountTypeFeatures(bankAccount.Type);

            try
            {
                bankAccount.RefillAmount(amount - features.RefillPrice);
                bankAccount.SetBonusFromOperation(_bonusCouter.GetBonusFromRefill((int)bankAccount.Type, amount));

                _bankAccountStorage.UpdateAccount(bankAccount.ToAccount());
            }
            catch (InsufficientFundsException ex)
            {
                throw new BankServiceException("An error occured while refill amount.", ex);
            }
            catch (AccountNotFoundException ex)
            {
                throw new BankServiceException("An error occured while updating in the storage.", ex);
            }
        }
예제 #3
0
 public void UpdateAccount(IAccount account)
 {
     _storage.UpdateAccount(account);
     _isDirty = true;
 }