コード例 #1
0
 public BankAccount(Person accountHolder, string accountName, string password)
 {
     AccountHolder = accountHolder;
     AccountName   = accountName;
     Iban          = IBANStorage.GenerateGermanIban();
     _password     = password;
 }
コード例 #2
0
 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();
 }
コード例 #3
0
ファイル: IBAN.cs プロジェクト: philipgrafat/Homework_Bank
        /// <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);
        }
コード例 #4
0
        public bool Login(IBAN iban, string password)
        {
            var account = BankStorage.GetAccount(iban);

            if (account.IsPasswordValid(password))
            {
                SessionAccount = account;
                return(true);
            }

            return(false);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: philipgrafat/Homework_Bank
        /// <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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 public BankAccount(Person accountHolder, string accountName, string password, IBAN iban) : this(accountHolder, accountName, password)
 {
     Iban = iban;
 }
コード例 #8
0
ファイル: IBAN.cs プロジェクト: philipgrafat/Homework_Bank
 public static void AddToStorage(IBAN iban) => UsedIbans.Add(iban);
コード例 #9
0
ファイル: IBAN.cs プロジェクト: philipgrafat/Homework_Bank
 public static bool DoesIbanAlreadyExist(IBAN toCheck) => UsedIbans.Contains(toCheck);
コード例 #10
0
 public static bool DoesAccountExist(IBAN withIban) => accountStorage.ContainsKey(withIban);
コード例 #11
0
 public static void DeleteAccount(IBAN withIban) => accountStorage.Remove(withIban);
コード例 #12
0
 public static BankAccount GetAccount(IBAN withIban) => accountStorage[withIban];
コード例 #13
0
 public CashTransaction(Money amount, IBAN receiverIban, string referenceText) : base(amount, Configuration.BankIban, receiverIban, referenceText)
 {
 }