Пример #1
0
        private void Transfer(BankCard bankCard)
        {
            if (IsEnterPin)
            {
                Console.Write("Enter the card number of the person to whom you want to send money: ");
                string card_number = Console.ReadLine();
                while (card_number.Length != 12)
                {
                    Console.Write("Enter the card number of the person to whom you want to send money: ");
                    card_number = Console.ReadLine();
                }
                if (bankDataBase.CheckForAccount(card_number))
                {
                    var card_owner_account = bankDataBase.GetBankAccount(bankCard.UniqueRoom);

                    Console.Write("Еnter the transfer amount: ");
                    decimal sum_of_transfer = Convert.ToDecimal(Console.ReadLine());

                    if (card_owner_account.Balance >= sum_of_transfer)
                    {
                        bankDataBase.TransferTo(card_number, bankCard.UniqueRoom, sum_of_transfer);
                        Console.WriteLine("The transfer was successful.");
                    }
                    else
                    {
                        Console.WriteLine("Not enough money.");
                    }
                }
                else
                {
                    Console.WriteLine("Such a card does not exist.");
                }
            }
            ChooseOperation(bankCard);
        }
Пример #2
0
        private void ChooseOperation(BankCard bankCard)
        {
            if (IsEnterPin)
            {
                Console.WriteLine("Select the operation you want to perform:\n\tTransfer: press 1\n\tEnd: press 0\n\tShow balance: press 2\n\t" +
                                  "Exit: press 3\n");
                if (Int32.TryParse(Console.ReadLine(), out int result))
                {
                    switch (result)
                    {
                    case 0:
                        Console.WriteLine("Thank you."); break;

                    case 1:
                        Transfer(bankCard); break;

                    case 2:
                        ShowBalance(bankCard); break;

                    case 3:
                        EndAndExit(bankCard); break;

                    default:
                        Console.WriteLine("This operation doesn't exist."); break;
                    }
                }
                else
                {
                    Console.WriteLine("Wrong type.");
                }
            }
        }
Пример #3
0
 public void Start(BankCard bankCard)
 {
     if (InputCardAndEnterPin(bankCard))
     {
         ChooseOperation(bankCard);
     }
 }
Пример #4
0
        private void ShowBalance(BankCard bankCard)
        {
            if (IsEnterPin)
            {
                var card_owner_account = bankDataBase.GetBankAccount(bankCard.UniqueRoom);
                Console.WriteLine("Your balance: " + card_owner_account.Balance + "$");

                ChooseOperation(bankCard);
            }
        }
Пример #5
0
 public bool CheckForAccount(BankCard bankCard)
 {
     if (bankAccounts.Any(x => x.BankCard == bankCard))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #6
0
 public BankAccount(CardHolder cardHolder)
 {
     if (cardHolder == null)
     {
         throw new ArgumentNullException(nameof(cardHolder), "Invalid user.");
     }
     else
     {
         AccountHolder = cardHolder;
         BankCard      = new BankCard(cardHolder);
     }
 }
Пример #7
0
 private bool InputCardAndEnterPin(BankCard bankCard)
 {
     if (bankDataBase.CheckForAccount(bankCard))
     {
         Console.Write("Enter pin code: ");
         string pin_code = Console.ReadLine();
         if (bankCard.CheckForCorrectPin(pin_code))
         {
             IsEnterPin = true;
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Пример #8
0
        private void EndAndExit(BankCard bankCard)
        {
            if (IsEnterPin)
            {
                Console.Write("End and exit? (<yes> or <no>): ");
                string result = Console.ReadLine();
                while (result != "yes" && result != "no")
                {
                    Console.Write("End and exit? (<yes> or <no>): ");
                    result = Console.ReadLine();
                }

                var card_owner_account = bankDataBase.GetBankAccount(bankCard.UniqueRoom);
                switch (result)
                {
                case "yes": Console.WriteLine($"Thank you and goodbye. {card_owner_account.AccountHolder.Name} " +
                                              $"{card_owner_account.AccountHolder.Surname}!");
                    break;

                case "no": ChooseOperation(bankCard); break;
                }
            }
        }