/// <summary> /// Removes a bank account from the storage. /// </summary> /// <param name="id">The bank account id.</param> /// <exception cref="ArgumentException"> /// Thrown when the <paramref name="id"/> less than 0. /// </exception> /// <exception cref="BankServiceException"> /// Thrown when the bank account with the <paramref name="id"/> not found or /// something wrong with removing from the storage. /// </exception> public void CloseBankAccount(int id) { if (id < 0) { throw new ArgumentException("The id must be greater than or equal to 0.", nameof(id)); } UpdateList(); BankAccount bankAccount = _bankAccounts.Find(x => x.ID == id); if (ReferenceEquals(bankAccount, null)) { throw new BankServiceException("No such bank account."); } try { _bankAccountStorage.RemoveAccount(bankAccount.ToAccount()); } catch (AccountNotFoundException ex) { throw new BankServiceException("An error occured while removing from the storage.", ex); } }
/// <summary> /// Removes an account with specified <paramref name="iban"/> from accounts file /// </summary> /// <param name="iban">IBAN of an account to close</param> /// <returns>account balance</returns> public decimal CloseAccount(string iban) { if (string.IsNullOrWhiteSpace(iban)) { throw new ArgumentException("No IBAN is given.", "IBAN"); } return(storage.RemoveAccount(iban)); }