/// <summary>
        /// Creates new bank account with specified type and adds it to the repository
        /// </summary>
        /// <param name="accountOwner">Account owner</param>
        /// <param name="accountID">Account ID</param>
        /// <param name="invoiceAmount">Invoice amount</param>
        /// <param name="bonusScores">Bonus Scores</param>
        /// <param name="accountType">Account type</param>
        private void Create(AccountOwner accountOwner, string accountID, decimal invoiceAmount, double bonusScores, AccountType accountType)
        {
            BankAccount newAccount;

            switch (accountType)
            {
            case AccountType.Base:
            {
                newAccount = new BaseAccount(accountOwner, accountID, invoiceAmount, bonusScores);
                repository.AddAccount(newAccount);
            }
            break;

            case AccountType.Gold:
            {
                newAccount = new SilverAccount(accountOwner, accountID, invoiceAmount, bonusScores);
                repository.AddAccount(newAccount);
            }
            break;

            case AccountType.Platinum:
            {
                newAccount = new PlatinumAccount(accountOwner, accountID, invoiceAmount, bonusScores);
                repository.AddAccount(newAccount);
            }
            break;

            default:
            {
                newAccount = new BaseAccount(accountOwner, accountID, invoiceAmount, bonusScores);
                repository.AddAccount(newAccount);
            }
            break;
            }
        }
        /// <summary>
        /// Create new account in repository
        /// </summary>
        /// <param name="name"></param>
        /// <param name="type">AccountType to choose what type of account we use</param>
        /// <param name="creator">Creates number for account</param>
        public void OpenAccount(string name, AccountType type, IAccountNumberCreateService creator)
        {
            Account acc;

            switch (type)
            {
            case AccountType.Base:
                acc = new BaseAccount(name, creator.GetNextNumber(name));
                break;

            case AccountType.Silver:
                acc = new SilverAccount(name, creator.GetNextNumber(name));
                break;

            case AccountType.Gold:     // Isn't implemented.
                acc = new SilverAccount(name, creator.GetNextNumber(name));
                break;

            default:
                acc = new BaseAccount(name, creator.GetNextNumber(name));
                break;
            }

            repos.AddToAccountList(acc);
            accountsCount++;
        }
        public Account OpenAccount(string owner, AccountType accountType, IAccountNumberCreateService creator)
        {
            Account account;

            string[] fullName = owner.Split();
            switch (accountType)
            {
            case AccountType.Base:
                account = new BaseAccount(creator.GenerateId(), fullName[0], fullName[1]);
                break;

            case AccountType.Silver:
                account = new SilverAccount(creator.GenerateId(), fullName[0], fullName[1]);
                break;

            case AccountType.Gold:
                account = new GoldAccount(creator.GenerateId(), fullName[0], fullName[1]);
                break;

            case AccountType.Platinum:
                account = new PlatinumAccount(creator.GenerateId(), fullName[0], fullName[1]);
                break;

            default:
                account = new BaseAccount(creator.GenerateId(), fullName[0], fullName[1]);
                break;
            }

            this.repository.AddAccount(account.ToDalAccount());
            return(account);
        }
        public void OpenAccount(string name, AccountType accountType, IAccountNumberCreateService accountNumberCreateService)
        {
            _ = name ?? throw new ArgumentNullException();
            _ = accountNumberCreateService ?? throw new ArgumentNullException();

            Account account;
            int     number = accountNumberCreateService.CreateAccountNumber();

            switch (accountType)
            {
            case AccountType.Base:
                account = new BaseAccount(number, name, 0, 0);
                break;

            case AccountType.Silver:
                account = new SilverAccount(number, name, 0, 0);
                break;

            case AccountType.Gold:
                account = new GoldAccount(number, name, 0, 0);
                break;

            case AccountType.Platinum:
                account = new PlatinumAccount(number, name, 0, 0);
                break;

            default:
                throw new ArgumentException();
            }

            accountRepository.Add(account);
        }
Example #5
0
        public static Account.Account Create(AccountHolder accountHolder, string id, TypeOfBankScore typeOfBankScore, Status status = Status.Open)
        {
            Account.Account account = null;

            switch (typeOfBankScore)
            {
            case TypeOfBankScore.Base:
                accountHolder.AddAccount(id);
                account        = new BaseAccount(id, accountHolder);
                account.Status = status;
                return(account);

            case TypeOfBankScore.Silver:
                accountHolder.AddAccount(id);
                account        = new SilverAccount(id, accountHolder);
                account.Status = status;
                return(account);

            case TypeOfBankScore.Gold:
                accountHolder.AddAccount(id);
                account        = new GoldAccount(id, accountHolder);
                account.Status = status;
                return(account);

            case TypeOfBankScore.Platinum:
                accountHolder.AddAccount(id);
                account         = new PlatinumAccount(id, accountHolder);
                account.Status  = status;
                account.Balance = 20;
                return(account);

            default:
                throw new ArgumentException($"Invalid {nameof(typeOfBankScore)}");
            }
        }
Example #6
0
        private IRequestAccountHandler ChainOfAccountsInitializer()
        {
            var account       = new ClassicAccount(new ClassicAccountBenefitsRepository());
            var silverAccount = new SilverAccount(new SilverAccountBenefitsRepository());
            var goldAccount   = new GoldAccount(new GoldAccountBenefitsRepository());

            account.Successor       = silverAccount;
            silverAccount.Successor = goldAccount;
            return(account);
        }
Example #7
0
        static void Main(string[] args)
        {
            BankAccount account = new SilverAccount(1234L, "Егор", "Кузьменков");

            account.DepositMoney(15);
            Console.WriteLine(account.AmountOfMoney);
            Console.WriteLine(account.BonusPoints);
            account.WithdrawMoney(10);
            Console.WriteLine(account.AmountOfMoney);
            Console.WriteLine(account.BonusPoints);
        }
Example #8
0
        public static void Main(string[] args)
        {
            BankAccount a = new BaseAccount(new AccountNumberGenerator(), new AccountHolder("Vanya", "Trashchenko", "*****@*****.**"));
            BankAccount b = new SilverAccount(new AccountNumberGenerator(), new AccountHolder("Vova", "Lenin", "*****@*****.**"));
            BankAccount c = new GoldAccount(new AccountNumberGenerator(), new AccountHolder("Sasha", "Pavlov", "*****@*****.**"));
            BankAccount d = new PlatinumAccount(new AccountNumberGenerator(), new AccountHolder("Katya", "Ivanova", "*****@*****.**"));

            a.Deposite(100);
            b.Deposite(100);
            c.Deposite(100);
            d.Deposite(100);

            IRepository rep = new Repository(a, b, c);

            rep.Save(d);
            rep.Delete(b);

            IService ser = new Service(rep);

            ser.OpenAccount(new AccountNumberGenerator(), new AccountHolder("Sasha", "Vrashchenko", "*****@*****.**"), new GoldAccountFactory());
            ser.OpenAccount(new AccountNumberGenerator(), new AccountHolder("Dasha", "Mrashchenko", "*****@*****.**"));

            // ser.Dump();

            foreach (var item in ser.Repository.Accounts)
            {
                Console.WriteLine(item.Id);
            }

            /*
             1427432362
             1292111581
             1369438661
             990816398
             746003708
            */

            ser.Deposite("746003708", 1000);
            // ser.Withdraw("990816398", 200); throws InvalidBalanceException

            ser.Transfer("746003708", "990816398", 1);

            ser.CloseAccount("1427432362");

            foreach (var item in ser.Repository.Accounts)
            {
                Console.WriteLine(item.ToString());
            }

            Console.ReadKey();
        }
 public static AccountBase CreateAccount(AccountType type)
 {
     AccountBase account = null;
     switch (type)
     {
         case AccountType.Silver:
             account = new SilverAccount();
             break;
         case AccountType.Gold:
             account=new GoldAccount();
             break;
         case AccountType.Platinum:
             account=new PlatinumAccount();
             break;
     }
     return account;
 }
        public static AccountBase CreateAccount(AccountType type)
        {
            AccountBase account = null;

            switch (type)
            {
            case AccountType.Silver:
                account = new SilverAccount();
                break;

            case AccountType.Gold:
                account = new GoldAccount();
                break;

            case AccountType.Platinum:
                account = new PlatinumAccount();
                break;
            }
            return(account);
        }
Example #11
0
        /// <summary>
        /// Opens the account.
        /// </summary>
        /// <param name="generator">The generator.</param>
        /// <param name="holder">The holder.</param>
        /// <param name="accountType">Type of the account.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">Null argument was sent</exception>
        /// <exception cref="System.ArgumentException">No such account type exists</exception>
        public static string OpenAccount(IAccountNumberGenerator generator, AccountHolder holder, string accountType)
        {
            if (generator == null || holder == null || accountType == null)
            {
                throw new ArgumentNullException("Null argument was sent");
            }

            BankAccount newAccount;

            switch (accountType.ToLower())
            {
            case "base":
            {
                Repository.Create(newAccount = new BaseAccount(holder, generator));
                break;
            }

            case "silver":
            {
                Repository.Create(newAccount = new SilverAccount(holder, generator));
                break;
            }

            case "gold":
            {
                Repository.Create(newAccount = new GoldAccount(holder, generator));
                break;
            }

            default:
            {
                throw new ArgumentException(nameof(accountType) + " is not defined");
            }
            }

            return(newAccount.IdNumber);
        }