示例#1
0
        /// <inheritdoc/>
        public void OpenAccount(string name, AccountType accountType, IAccountBonus bonusType, IAccountNumberCreateService createService)
        {
            BankAccount newAccount = null;

            int id = createService.CreateId();

            while (this.Accounts.Any(a => a.AccountNumber == id))
            {
                id = createService.CreateId();
            }

            switch (accountType)
            {
            case AccountType.Base:
                newAccount = new BaseBankAccount(id, name, bonusType);
                break;

            case AccountType.Silver:
                newAccount = new SilverBankAccount(id, name, bonusType);
                break;

            case AccountType.Gold:
                newAccount = new GoldBankAccount(id, name, bonusType);
                break;
            }

            this.Accounts.Add(newAccount);

            this.SaveAccountsToStorage();
        }
示例#2
0
        /// <summary>
        /// Initializes bank service.
        /// </summary>
        /// <param name="bankService">
        /// Bank service to initialize.
        /// </param>
        private static void Init(BankService bankService)
        {
            BankAccount account1 = new BaseBankAccount(1, "Eduard Adasko");

            account1 = new BaseBonus(account1);
            account1 = new HolidayBonus(account1);

            BankAccount account2 = new GoldBankAccount(2, "Polina Ushakova");

            account2 = new HolidayBonus(account2);

            bankService.AddAccount(account1);
            bankService.AddAccount(account2);
        }
 /// <summary>
 /// Method for adding new account into Account repository
 /// </summary>
 /// <param name="client">Owner of account</param>
 /// <param name="startAmount">Value of start amount</param>
 public void Create(Client client, decimal startAmount)
 {
     if (startAmount >= 0m && startAmount < 1000m)
     {
         var account = new BaseBankAccount(client, startAmount);
         bankAccounts.Add(account);
     }
     else if (startAmount >= 1000m && startAmount < 5000m)
     {
         var account = new SilverBankAccount(client, startAmount);
         bankAccounts.Add(account);
     }
     else if (startAmount >= 5000m && startAmount < 10000m)
     {
         var account = new GoldBankAccount(client, startAmount);
         bankAccounts.Add(account);
     }
     else if (startAmount >= 10000m)
     {
         var account = new PlatinumBankAccount(client, startAmount);
         bankAccounts.Add(account);
     }
 }
示例#4
0
        public static void Main(string[] args)
        {
            BaseBankAccount     firstBankAccount  = new BaseBankAccount(1234, "Vinnichek Ira");
            GoldBankAccount     secondBankAccount = new GoldBankAccount(3456, "Petrov Petya");
            PlatinumBankAccount thirdBankAccount  = new PlatinumBankAccount(4567, "Ivanov Ivan");
            PlatinumBankAccount fourthBankAccount = new PlatinumBankAccount(4567, "Ivanov Ivan");

            Console.WriteLine(firstBankAccount);

            Console.WriteLine(firstBankAccount.Equals(secondBankAccount)); //false
            Console.WriteLine(thirdBankAccount.Equals(fourthBankAccount)); //true

            firstBankAccount.ReplenishBalance(1000);
            secondBankAccount.ReplenishBalance(1000);
            thirdBankAccount.ReplenishBalance(1000);
            thirdBankAccount.WithdrawMoney(200);

            BankAccountService service = new BankAccountService();

            service.AddBankAccount(firstBankAccount);
            service.AddBankAccount(secondBankAccount);
            Console.WriteLine(service);

            service.RemoveBankAccount(secondBankAccount);
            Console.WriteLine(service);

            service.AddBankAccount(secondBankAccount);
            service.AddBankAccount(thirdBankAccount);

            Console.WriteLine("\r\n");
            Console.WriteLine("------List of bank accounts.------");
            Console.WriteLine(service);

            IBankAccountStorage binaryStorage = new BankAccountBinaryStorage(@"/Users/vinnichek/Projects/Task/ConsoleAppForBankAccount/BankAccounts.txt");
            //service.SaveToStorage(binaryStorage);
            //service.LoadFromStorage(binaryStorage);
        }