/// <summary> /// Makes a withdrawal of <paramref name="amount"/> from an account with specified <paramref name="iban"/> /// </summary> /// <param name="iban">IBAN of an account to make withdrawal</param> /// <param name="amount">withdrawal amount</param> /// <returns>new account balance</returns> /// <exception cref="ArgumentException">withdrawal amount is lesser than minimal</exception> public decimal MakeWithdrawal(string iban, decimal amount) { if (string.IsNullOrWhiteSpace(iban)) { throw new ArgumentException("No IBAN is given.", "IBAN"); } if (amount < MINWITHDRAWAL) { throw new ArgumentException("Minimum withdrawal amount is " + MINWITHDRAWAL.ToString("C")); } var account = BankAccountMapper.FromDTO(Storage.GetAccount(iban)); if (amount > account.Balance) { throw new InvalidOperationException("account balance is less than withdrawal amount"); } account.Balance -= amount; account.BonusPoints -= BonusCalculator.CalculateWithdrawalBonus(account, amount); Storage.UpdateAccount(BankAccountMapper.ToDTO(account)); return(account.Balance); }
/// <summary> /// Makes a deposit of <paramref name="amount"/> to an account with specified <paramref name="iban"/>. /// </summary> /// <param name="iban">IBAN of an account to make deposit</param> /// <param name="amount">deposit amount</param> /// <returns>new account balance</returns> /// <exception cref="ArgumentException">deposit amount is lesser than minimal</exception> public decimal MakeDeposit(string iban, decimal amount) { if (string.IsNullOrWhiteSpace(iban)) { throw new ArgumentException("No IBAN is given.", "IBAN"); } if (amount < MINDEPOSIT) { throw new ArgumentException("Minimum deposit amount is " + MINDEPOSIT.ToString("C")); } var account = BankAccountMapper.FromDTO(Storage.GetAccount(iban)); account.Balance += amount; account.BonusPoints += BonusCalculator.CalculateDepositBonus(account, amount); Storage.UpdateAccount(BankAccountMapper.ToDTO(account)); return(account.Balance); }