/// <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(); }
/// <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, });
/// <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; }
/// <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) { }
/// <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) { }
/// <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; }
/// <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; }