Пример #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>
        /// Converts DTO account to BLL account.
        /// </summary>
        /// <param name="dtoAccount">Account for converting.</param>
        /// <returns>Converted account.</returns>
        public static BankAccount ConvertToBankAccount(this DTO_BankAccount dtoAccount)
        {
            IAccountBonus bonusProgram = dtoAccount.BonusType switch
            {
                BonusType.Base => new BaseAccountBonus(),
                BonusType.Extra => new ExtraAccountBonus(),
                _ => throw new ArgumentException(),
            };

            return(dtoAccount.AccountType switch
            {
                AccountType.Base => new BaseBankAccount(
                    dtoAccount.AccountNumber,
                    dtoAccount.OwnerName,
                    dtoAccount.Balance,
                    dtoAccount.BonusPoints,
                    bonusProgram),

                AccountType.Gold => new GoldBankAccount(
                    dtoAccount.AccountNumber,
                    dtoAccount.OwnerName,
                    dtoAccount.Balance,
                    dtoAccount.BonusPoints,
                    bonusProgram),

                AccountType.Silver => new SilverBankAccount(
                    dtoAccount.AccountNumber,
                    dtoAccount.OwnerName,
                    dtoAccount.Balance,
                    dtoAccount.BonusPoints,
                    bonusProgram),

                _ => null,
            });
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BankAccount"/> class.
 /// </summary>
 /// <param name="id">
 /// Id value.
 /// </param>
 /// <param name="name">
 /// Owner name value.
 /// </param>
 protected BankAccount(int id, string name)
 {
     this.AccountNumber = id;
     this.OwnerName     = name;
     this.Balance       = 0;
     this.BonusPoints   = 0;
     this.bonusProgram  = null;
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseBankAccount"/> class.
 /// </summary>
 /// <param name="id">Id value.</param>
 /// <param name="name">Owner name value.</param>
 /// <param name="bonusProgram">Type od bonus program.</param>
 public BaseBankAccount(int id, string name, IAccountBonus bonusProgram)
     : base(id, name, bonusProgram)
 {
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseBankAccount"/> class.
 /// </summary>
 /// <param name="id">
 /// Id value.
 /// </param>
 /// <param name="name">
 /// Owner name value.
 /// </param>
 /// <param name="balance">
 /// Balance value.
 /// </param>
 /// <param name="bonusPoints">
 /// Bonus points value.
 /// </param>
 /// <param name="bonusProgram">
 /// Type of bonus program.
 /// </param>
 public BaseBankAccount(int id, string name, decimal balance, double bonusPoints, IAccountBonus bonusProgram)
     : base(id, name, balance, bonusPoints, bonusProgram)
 {
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BankAccount"/> class.
 /// </summary>
 /// <param name="id">
 /// Id value.
 /// </param>
 /// <param name="name">
 /// Owner name value.
 /// </param>
 /// <param name="balance">
 /// Balance value.
 /// </param>
 /// <param name="bonusPoints">
 /// Bonus points value.
 /// </param>
 /// <param name="bonusProgram">Type of bonus program.</param>
 protected BankAccount(int id, string name, decimal balance, double bonusPoints, IAccountBonus bonusProgram)
     : this(id, name, bonusProgram)
 {
     this.Balance     = balance;
     this.BonusPoints = bonusPoints;
 }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BankAccount"/> class.
 /// </summary>
 /// <param name="id">Id value.</param>
 /// <param name="name">Owner name value.</param>
 /// <param name="bonusProgram">Type of bonus program.</param>
 protected BankAccount(int id, string name, IAccountBonus bonusProgram) : this(id, name)
 {
     bonusProgram.Account = this;
     this.BonusType       = bonusProgram.BonusType;
     this.bonusProgram    = bonusProgram;
 }