public BankAccount(Person accountHolder, string accountName, string password) { AccountHolder = accountHolder; AccountName = accountName; Iban = IBANStorage.GenerateGermanIban(); _password = password; }
public Transaction(Money amount, IBAN senderIban, IBAN receiverIban, string referenceText) { Amount = amount; SenderIban = senderIban; ReceiverIban = receiverIban; ReferenceText = referenceText.PadRight(15, ' ').Substring(0, 15); // Max 15 chars DateTime = DateTime.Now; ID = Guid.NewGuid(); }
/// <summary> /// Generates a German IBAN Number /// </summary> /// <param name="bankCode">8-digit Bank Code</param> /// <param name="accountNumber">10 digit Bank Account Number</param> /// <returns>German IBAN Number</returns> public static IBAN GenerateGermanIban(int bankCode, long accountNumber) { // Currently only working for German IBANS as there are different formats in every country var countryCode = CountryCode.DE; var checkSum = GetIbanCheckSum(bankCode, accountNumber, countryCode); var iban = new IBAN(countryCode, checkSum, bankCode, accountNumber); AddToStorage(iban); return(iban); }
public bool Login(IBAN iban, string password) { var account = BankStorage.GetAccount(iban); if (account.IsPasswordValid(password)) { SessionAccount = account; return(true); } return(false); }
/// <summary> /// Prompts for an valid existing IBAN number. /// </summary> /// <returns>IBAN. If it has no value, operation should be quit</returns> private static IBAN?PromptForIban() { bool ibanCanLogin = false; IBAN?iban = null; while (!ibanCanLogin) { Console.WriteLine("IBAN:[q to exit] "); var ibanInput = Console.ReadLine(); ibanInput = Regex.Replace(ibanInput, @"\s+", ""); // Remove Whitespaces if (ibanInput == "q") { return(null); } if (ibanInput.Length != 22) { Console.WriteLine("IBAN must be 22 characters long!\n"); continue; } try { iban = new IBAN(ibanInput); } catch (ArgumentException) { Console.WriteLine("IBAN is invalid!\n"); } if (!iban.HasValue) { continue; } if (BankStorage.DoesAccountExist(iban.Value)) { ibanCanLogin = true; } else { Console.WriteLine("Account does not exist or is not registered!\n"); } } return(iban); }
public BankTransactionState TransferMoney(Money amount, IBAN to, string referenceText) { if (SessionAccount == null) { return(BankTransactionState.NotLoggedIn); } var transaction = new Transaction(amount, SessionAccount.Iban, to, referenceText); var receiver = BankStorage.GetAccount(to); SessionAccount.Transfer(transaction); receiver.Transfer(transaction); BankStorage.AddTransaction(transaction); BankStorage.AddAccount(receiver); SaveSession(); return(BankTransactionState.Success); }
public BankAccount(Person accountHolder, string accountName, string password, IBAN iban) : this(accountHolder, accountName, password) { Iban = iban; }
public static void AddToStorage(IBAN iban) => UsedIbans.Add(iban);
public static bool DoesIbanAlreadyExist(IBAN toCheck) => UsedIbans.Contains(toCheck);
public static bool DoesAccountExist(IBAN withIban) => accountStorage.ContainsKey(withIban);
public static void DeleteAccount(IBAN withIban) => accountStorage.Remove(withIban);
public static BankAccount GetAccount(IBAN withIban) => accountStorage[withIban];
public CashTransaction(Money amount, IBAN receiverIban, string referenceText) : base(amount, Configuration.BankIban, receiverIban, referenceText) { }