コード例 #1
0
        public bool Login(IBAN iban, string password)
        {
            var account = BankStorage.GetAccount(iban);

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

            return(false);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: philipgrafat/Homework_Bank
        /// <summary>
        /// Displays the money transfer dialog.
        /// </summary>
        private static void TransferMoneyDialog()
        {
            Console.Clear();
            WriteHeader();
            Console.WriteLine("Transfer money to another account\n");

            double amountValue;

            do
            {
                Console.WriteLine("Enter the amount in euros you want to transfer: ");
            } while (!double.TryParse(Console.ReadLine(), out amountValue) || amountValue <= 0);

            var amount = new Money(amountValue, CurrencyCode.EUR);

            Console.WriteLine("\nEnter the IBAN of the account you want to transfer the money to:");
            var iban = PromptForIban();

            if (!iban.HasValue)
            {
                return;
            }

            Console.WriteLine("\nEnter a payment reference: ");
            var reference = Console.ReadLine();

            Console.Clear();

            Console.WriteLine($"Receiver: {BankStorage.GetAccount(iban.Value).AccountHolder} <{iban.Value}>");
            Console.WriteLine($"Amount: {amount}");
            Console.WriteLine($"Reference: {reference}");

            Console.WriteLine("\nDo you really want to start the transaction? [y/n]");
            var confirmation = Console.ReadLine();

            if (confirmation != "y")
            {
                return;
            }

            Console.WriteLine(currentClerk.TransferMoney(amount, iban.Value, reference) == BankTransactionState.Success
                ? "Success! Press any key to continue..."
                : "Something went wrong! Please try again later. Press any key to continue...");

            Console.ReadKey();
        }
コード例 #3
0
        public BankTransactionState PutMoney(Money amount)
        {
            if (SessionAccount == null)
            {
                return(BankTransactionState.NotLoggedIn);
            }

            var transaction = new CashTransaction(amount, SessionAccount.Iban, "bar deposit");

            var receiver = BankStorage.GetAccount(SessionAccount.Iban);

            receiver.Transfer(transaction);

            BankStorage.AddAccount(receiver);

            SaveSession();

            return(BankTransactionState.Success);
        }
コード例 #4
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);
        }