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(IAccountNumberGenerator gen, AccountHolder person, AccountType priveledge, AccountStatus status, int sum, int bonus, out string id) { BankAccount bankAccount; id = gen.GenerateAccountNumber(person + " " + priveledge); switch ((int)priveledge) { case 1: { bankAccount = new BaseAccount(int.Parse(id), person, status, priveledge, sum, bonus); break; } case 2: { bankAccount = new GoldAccount(int.Parse(id), person, status, priveledge, sum, bonus); break; } case 3: { bankAccount = new PlatinumAccount(int.Parse(id), person, status, priveledge, sum, bonus); break; } default: { bankAccount = new BaseAccount(int.Parse(id), person, status, priveledge, sum, bonus); break; } } bankAccount.Status = AccountStatus.Active; fakeRepository.Create(bankAccount); }
/// <summary> /// Opens a new account for <paramref name="holder"/> with <paramref name="startBalance"/>. /// </summary> /// <param name="holder">person's full name</param> /// <param name="startBalance">first deposit amount</param> /// <returns>IBAN of a new account</returns> /// <exception cref="ArgumentException">Start balance is lesser than minimal.</exception> public string OpenNewAccount(string holder, decimal startBalance) { if (string.IsNullOrWhiteSpace(holder)) { throw new ArgumentException("No significant characters are given.", "holder"); } if (startBalance < MINDEPOSIT) { throw new ArgumentException($"Cannot create a bank account with balance lesser than {MINDEPOSIT}"); } BankAccount account; if (startBalance <= 1000) { account = new StandardAccount(ibanGenerator.GenerateIBAN(), holder, startBalance, bonusPoints: 0); } else if (startBalance <= 10000) { account = new GoldAccount(ibanGenerator.GenerateIBAN(), holder, startBalance, bonusPoints: 5); } else { account = new PlatinumAccount(ibanGenerator.GenerateIBAN(), holder, startBalance, bonusPoints: 10); } storage.AddAccount(account); return(account.IBAN); }
private BankAccount UpdateAccounts(BankAccount account, bool isClosed = false, int amount = 0, int bonus = 0) { if (account == null) { throw new ArgumentNullException(nameof(account)); } BankAccount newAccount; switch (account.TypeAccount) { case BankAccountType.Base: newAccount = new BaseAccount(account.User, account.AccountId, account.TypeAccount, (uint)(account.Amount + amount), (uint)(account.Bonus + bonus), isClosed); break; case BankAccountType.Gold: newAccount = new GoldAccount(account.User, account.AccountId, account.TypeAccount, (uint)(account.Amount + amount), (uint)(account.Bonus + bonus), isClosed); break; case BankAccountType.Platinum: newAccount = new PlatinumAccount(account.User, account.AccountId, account.TypeAccount, (uint)(account.Amount + amount), (uint)(account.Bonus + bonus), isClosed); break; default: throw new InvalidEnumArgumentException(nameof(account.TypeAccount)); } return(newAccount); }
private BankAccount CreateAccounts(string accountId, string userId, string firstName, string lastName, BankAccountType typeAccount, uint amount, uint bonus, bool isClosed) { BankAccount newAccount; BankUser bankUser = new BankUser(userId, firstName, lastName); switch (typeAccount) { case BankAccountType.Base: newAccount = new BaseAccount(bankUser, accountId, typeAccount, amount, bonus, isClosed); break; case BankAccountType.Gold: newAccount = new GoldAccount(bankUser, accountId, typeAccount, amount, bonus, isClosed); break; case BankAccountType.Platinum: newAccount = new PlatinumAccount(bankUser, accountId, typeAccount, amount, bonus, isClosed); break; default: throw new InvalidEnumArgumentException(nameof(typeAccount)); } return(newAccount); }
/// <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(Mappers.BankAccountsMapper.ToDalBankAccount(newAccount, AccountType.Base)); } break; case AccountType.Platinum: { newAccount = new PlatinumAccount(accountOwner, accountID, invoiceAmount, bonusScores); repository.AddAccount(Mappers.BankAccountsMapper.ToDalBankAccount(newAccount, AccountType.Platinum)); } break; case AccountType.Gold: { newAccount = new GoldAccount(accountOwner, accountID, invoiceAmount, bonusScores); repository.AddAccount(Mappers.BankAccountsMapper.ToDalBankAccount(newAccount, AccountType.Gold)); } break; default: { newAccount = new BaseAccount(accountOwner, accountID, invoiceAmount, bonusScores); repository.AddAccount(Mappers.BankAccountsMapper.ToDalBankAccount(newAccount, AccountType.Base)); } break; } }
private BankAccount CreateAccountByType(BankUser bankUser, BankAccountType typeAccount) { if (bankUser == null) { throw new ArgumentNullException(nameof(bankUser)); } BankAccount newAccount; switch (typeAccount) { case BankAccountType.Base: newAccount = new BaseAccount(bankUser); break; case BankAccountType.Gold: newAccount = new GoldAccount(bankUser); break; case BankAccountType.Platinum: newAccount = new PlatinumAccount(bankUser); break; default: throw new InvalidEnumArgumentException(nameof(typeAccount)); } return(newAccount); }
/// <summary> /// Opens the account. /// </summary> /// <param name="user">The user.</param> /// <param name="accountType">The type of account.</param> /// <param name="id">The identifier.</param> public void OpenAccount(User user, AccountType accountType) { BankAccount bankAccount; string id = this.GenerateAccountId(user.ToString() + " " + accountType.ToString()); switch ((int)accountType) { case 0: { bankAccount = new BaseAccount(id, user, accountType, AccountStatus.Open, 0, 0); break; } case 1: { bankAccount = new GoldAccount(id, user, accountType, AccountStatus.Open, 0, 0); break; } case 2: { bankAccount = new PlatinumAccount(id, user, accountType, AccountStatus.Open, 0, 0); break; } default: { bankAccount = new BaseAccount(id, user, accountType, AccountStatus.Open, 0, 0); break; } } bankAccount.Status = AccountStatus.Open; this.bankAccounts.Create(bankAccount); }
public void Add(string accType, string name, string lastname) { using (AcountStorageDB db = new AcountStorageDB()) { Account acc = new BaseAccount(name, lastname); switch (accType) { case "Basic": acc = new BaseAccount(name, lastname); break; case "Gold": acc = new GoldAccount(name, lastname); break; case "Platinum": acc = new PlatinumAccount(name, lastname); break; } AcountModel acount = new AcountModel(); acount.accid = acc.AccId; acount.ownerName = acc.OwnerName; acount.ownerLastname = acc.OwnerLastName; acount.balance = acc.Balance; acount.bonusPoints = acc.BonusPoints; acount.acouintType = accType; } }
/// <summary> /// Opens the account. /// </summary> /// <param name="user">The user.</param> /// <param name="accountType">The type of account.</param> /// <param name="id">The identifier.</param> public void OpenAccount(User user, AccountType accountType, out int id) { BankAccount bankAccount; switch ((int)accountType) { case 0: { bankAccount = new BaseAccount(user, accountType, AccountStatus.Open, 0, 0); break; } case 1: { bankAccount = new GoldAccount(user, accountType, AccountStatus.Open, 0, 0); break; } case 2: { bankAccount = new PlatinumAccount(user, accountType, AccountStatus.Open, 0, 0); break; } default: { bankAccount = new BaseAccount(user, accountType, AccountStatus.Open, 0, 0); break; } } bankAccount.Status = AccountStatus.Open; this.bankAccounts.Create(bankAccount); id = bankAccount.Id; }
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); }
/// <summary> /// Creates new account of the given type and adds it to the storage /// </summary> /// <param name="accType"></param> /// <param name="owner"></param> /// <returns>account's id</returns> public string CreateNewAccount(AccountTypes accType, AccountOwner owner, IidGenerator generator, IPointsCounter counter) { if (owner == null) { throw new ArgumentNullException(); } Account newAcc; switch (accType) { case AccountTypes.Basic: currStorage.Add(newAcc = new BaseAccount(owner, generator, counter)); break; case AccountTypes.Golden: currStorage.Add(newAcc = new GoldenAccount(owner, generator, counter)); break; case AccountTypes.Platinum: currStorage.Add(newAcc = new PlatinumAccount(owner, generator, counter)); break; default: throw new Exception("Can't create an account"); } return(newAcc.Accid); }
public static BankAccount ToBankAccount(DalBankAccount dalBankAccount) { BankAccount bankAccount; switch (dalBankAccount.AccountType) { case AccountType.Base: { bankAccount = new BaseAccount(AccountOwnersMapper.ToAccountOwner(dalBankAccount.AccountOwner), dalBankAccount.BankAccountNumber, dalBankAccount.InvoiceAmount, dalBankAccount.BonusScores, dalBankAccount.IsClosed); } break; case AccountType.Platinum: { bankAccount = new PlatinumAccount(AccountOwnersMapper.ToAccountOwner(dalBankAccount.AccountOwner), dalBankAccount.BankAccountNumber, dalBankAccount.InvoiceAmount, dalBankAccount.BonusScores, dalBankAccount.IsClosed); } break; case AccountType.Gold: { bankAccount = new GoldAccount(AccountOwnersMapper.ToAccountOwner(dalBankAccount.AccountOwner), dalBankAccount.BankAccountNumber, dalBankAccount.InvoiceAmount, dalBankAccount.BonusScores, dalBankAccount.IsClosed); } break; default: { bankAccount = new BaseAccount(AccountOwnersMapper.ToAccountOwner(dalBankAccount.AccountOwner), dalBankAccount.BankAccountNumber, dalBankAccount.InvoiceAmount, dalBankAccount.BonusScores, dalBankAccount.IsClosed); } break; } return(bankAccount); }
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)}"); } }
/// <summary> /// Opens a new account for <paramref name="owner"/> with <paramref name="startBalance"/>. /// </summary> /// <param name="owner">person's full name</param> /// <param name="startBalance">first deposit amount</param> /// <returns>IBAN of a new account</returns> /// <exception cref="ArgumentException">Start balance is lesser than minimal.</exception> public string OpenAccount(AccountOwner owner, decimal startBalance) { if (owner == null) { throw new ArgumentNullException(nameof(owner)); } BankAccount account; if (startBalance < 1000) { account = new StandardAccount(ibanGenerator.GenerateIBAN(), owner, startBalance, bonusPoints: 0); } else if (startBalance < 10000) { account = new GoldAccount(ibanGenerator.GenerateIBAN(), owner, startBalance, bonusPoints: 5); } else { account = new PlatinumAccount(ibanGenerator.GenerateIBAN(), owner, startBalance, bonusPoints: 10); } accountsRepo.Accounts.Create(account.ToDTO()); accountsRepo.Save(); return(account.IBAN); }
private List <BankAccount> ReadFromFile() { List <BankAccount> bankAccounts = new List <BankAccount>(); try { using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.OpenOrCreate))) { while (reader.PeekChar() > -1) { string id = reader.ReadString(); int status = reader.ReadInt32(); decimal balance = reader.ReadDecimal(); int bonusPoints = reader.ReadInt32(); string userFirstName = reader.ReadString(); string userLastName = reader.ReadString(); int accountType = reader.ReadInt32(); User user = new User(userFirstName, userLastName); BankAccount bankAccount; switch ((int)accountType) { case 0: { bankAccount = new BaseAccount(id, user, (AccountType)accountType, (AccountStatus)status, balance, bonusPoints); break; } case 1: { bankAccount = new GoldAccount(id, user, (AccountType)accountType, (AccountStatus)status, balance, bonusPoints); break; } case 2: { bankAccount = new PlatinumAccount(id, user, (AccountType)accountType, (AccountStatus)status, balance, bonusPoints); break; } default: { bankAccount = new BaseAccount(id, user, (AccountType)accountType, (AccountStatus)status, balance, bonusPoints); break; } } bankAccounts.Add(bankAccount); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(bankAccounts); }
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(); }
/// <summary> /// Determines the type of account for its creation. /// </summary> /// <param name="_id">Bank account's id.</param> /// <param name="firstName">Bank account's first name.</param> /// <param name="lastName">Bank account's last name.</param> /// <param name="phone">Bank account's phone number.</param> /// <param name="status">Bank account's status.</param> /// <param name="type">Bank account's type.</param> /// <param name="sum">Bank account's first added sum.</param> /// <param name="points">Bank account's first added points.</param> /// <returns>Bank account instance.</returns> internal BankAccount DefineAccount(int _id, string firstName, string lastName, string phone, AccountStatus status, AccountType type, int sum, int points) { BankAccount account = null; switch (type) { case AccountType.Base: account = new BaseAccount(_id, new AccountHolder(firstName, lastName, phone), status, type, sum, points); break; case AccountType.Gold: account = new GoldAccount(_id, new AccountHolder(firstName, lastName, phone), status, type, sum, points); break; case AccountType.Premium: account = new PlatinumAccount(_id, new AccountHolder(firstName, lastName, phone), status, type, sum, points); 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; }
public List <Account> GetAccounts() { using (AcountStorageDB db = new AcountStorageDB()) { List <AcountModel> tempacc = db.Acounts.ToList(); if (tempacc != null) { List <Account> listaccs = new List <Account>(); foreach (AcountModel acc in tempacc) { Account accentity; switch (acc.acouintType) { case "Basic": accentity = new BaseAccount(acc.ownerName, acc.ownerLastname, acc.accid); break; case "Gold": accentity = new GoldAccount(acc.ownerName, acc.ownerLastname, acc.accid); break; case "Platinum": accentity = new PlatinumAccount(acc.ownerName, acc.ownerLastname, acc.accid); break; default: accentity = new BaseAccount(acc.ownerName, acc.ownerLastname, acc.accid); break; } accentity.BonusPoints = acc.bonusPoints; accentity.Balance = acc.balance; listaccs.Add(accentity); } return(listaccs); } else { throw new Exception(); } } }
private static void CreateAccount(string[] args) { switch (GetAccountType()) { case 1: var savingsAccount = new SavingsAccount(); savingsAccount .Create(GetFirstName(), GetLastName(), GetIdNumber(), GetPay(savingsAccount.MinimumPay, args)); var initialDeposit = InitialDeposit(); if (initialDeposit >= savingsAccount.BookBalance) { savingsAccount.Deposit(initialDeposit); SavingsAccounts.Add(savingsAccount); Console.WriteLine(savingsAccount.ToString()); } else { Console.WriteLine($"Initial deposit must be a minimum of {savingsAccount.BookBalance}"); } Main(args); break; case 2: var currentAccount = new CurrentAccount(); currentAccount.Create(GetFirstName(), GetLastName(), GetIdNumber(), GetPay(currentAccount.MinimumPay, args)); currentAccount.Deposit(InitialDeposit()); CurrentAccounts.Add(currentAccount); Console.WriteLine(currentAccount.ToString()); Main(args); break; case 3: var platinumAccount = new PlatinumAccount(); platinumAccount .Create(GetFirstName(), GetLastName(), GetIdNumber(), GetPay(platinumAccount.MinimumPay, args)); platinumAccount.Deposit(InitialDeposit()); PlatinumAccounts.Add(platinumAccount); Console.WriteLine(platinumAccount.ToString()); Main(args); break; } }
/// <summary> /// Creates new account. /// </summary> /// <param name="name">Name of account's owner.</param> /// <param name="accountType">Type of account.</param> /// <param name="creator">Service for creating number of account.</param> public void OpenAccount(string name, string email, AccountType accountType, IAccountNumberCreateService creator) { Account account = null; switch (accountType) { case AccountType.Base: account = new BaseAccount(creator.Create(accountNum++), name, email); break; case AccountType.Gold: account = new GoldAccount(creator.Create(accountNum++), name, email); break; case AccountType.Platinum: account = new PlatinumAccount(creator.Create(accountNum++), name, email); break; } repository.Create(account.ToAccountDto()); }
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 Account ToAccount(this AccountDto account) { Account result = null; AccountType accountType = (AccountType)account.AccountType; switch (accountType) { case AccountType.Base: result = new BaseAccount(account.Number, account.Name, account.Email, account.Balance, account.Points); break; case AccountType.Gold: result = new GoldAccount(account.Number, account.Name, account.Email, account.Balance, account.Points); break; case AccountType.Platinum: result = new PlatinumAccount(account.Number, account.Name, account.Email, account.Balance, account.Points); break; } return(result); }
public Account Create(AccountType type, Person owner, IGenerateId generator) { Account newAccount = null; switch (type) { case AccountType.Base: newAccount = new BaseAccount(owner, generator); break; case AccountType.Gold: newAccount = new GoldAccount(owner, generator); break; case AccountType.Platinum: newAccount = new PlatinumAccount(owner, generator); break; } return(newAccount); }
public static Account Create(AccountType type, Person owner, string number, decimal sum, bool isClosed) { Account newAccount = null; switch (type) { case AccountType.Base: newAccount = new BaseAccount(owner, number, sum, isClosed); break; case AccountType.Gold: newAccount = new GoldAccount(owner, number, sum, isClosed); break; case AccountType.Platinum: newAccount = new PlatinumAccount(owner, number, sum, isClosed); break; } return(newAccount); }
/// <summary> /// Creates an instance of the object type <paramref name="type"/> /// </summary> /// <param name="type">Object type <see cref="AccountType"/></param> /// <param name="number">Account number.</param> /// <param name="lastName">Last Name</param> /// <param name="firstName">First Name</param> /// <param name="balance">Balance</param> /// <param name="bonus">Bonus</param> /// <exception cref="AccountCreatorException"> /// It is thrown in the case of an unknown object type. /// </exception> /// <returns> /// A new type entity <see cref="BankAccount"/> /// </returns> public static BankAccount CreateAccount(AccountType type, string number, string lastName, string firstName, decimal balance, int bonus) { if (number == null) { throw new System.ArgumentNullException(nameof(number)); } if (lastName == null) { throw new System.ArgumentNullException(nameof(lastName)); } if (firstName == null) { throw new System.ArgumentNullException(nameof(firstName)); } BankAccount account; switch (type) { case AccountType.BaseAccount: account = new BaseAccount(number, lastName, firstName, balance, bonus); break; case AccountType.GoldAccount: account = new GoldAccount(number, lastName, firstName, balance, bonus); break; case AccountType.PlatinumAccount: account = new PlatinumAccount(number, lastName, firstName, balance, bonus); break; default: throw new AccountCreatorException($"{nameof(type)}Unknown account type."); } return(account); }
public Account GetByID(string id) { using (AcountStorageDB db = new AcountStorageDB()) { AcountModel acc = db.Acounts.SingleOrDefault(t => t.accid == id); if (acc != null) { Account accentity; switch (acc.acouintType) { case "Basic": accentity = new BaseAccount(acc.ownerName, acc.ownerLastname, acc.accid); break; case "Gold": accentity = new GoldAccount(acc.ownerName, acc.ownerLastname, acc.accid); break; case "Platinum": accentity = new PlatinumAccount(acc.ownerName, acc.ownerLastname, acc.accid); break; default: accentity = new BaseAccount(acc.ownerName, acc.ownerLastname, acc.accid); break; } accentity.BonusPoints = acc.bonusPoints; accentity.Balance = acc.balance; return(accentity); } else { throw new ArgumentException("There are no Account with such id:" + id); } } }
public string OpenAccount(string email, AccountType accountType, IAccountNumberCreator creator) { Account account; string accountNumber = creator.Create(); switch (accountType) { case AccountType.Base: account = new BaseAccount(accountNumber); break; case AccountType.Gold: account = new GoldAccount(accountNumber); break; case AccountType.Platinum: account = new PlatinumAccount(accountNumber); break; default: account = new BaseAccount(accountNumber); break; } account.OwnerEmail = email; repository.AddAccount(EntityConverter.ToDalAccount(account)); var mail = new MailMessage() { Subject = "Add account", Body = $"New account was added. Account number: {accountNumber}", IsBodyHtml = true }; mail.To.Add(email); mailService.SendMail(mail); return(accountNumber); }
/// <summary> /// Open a new bank account. /// </summary> /// <param name="generator">Generates the account id.</param> /// <param name="holder">Holder of the account.</param> /// <param name="accountType">Type of the account.</param> /// <returns>Id of the created account.</returns> /// <exception cref="ArgumentNullException">Some argument is null.</exception> /// <exception cref="ArgumentException">The account type is not defined./exception> public string OpenAccount(IAccountIdGenerator generator, AccountHolder holder, string accountType) { if (generator == null || holder == null || accountType == null) { throw new ArgumentNullException(); } BankAccount account = null; switch (accountType.ToLower()) { case "base": { _storage?.AddBankAccount(account = new BaseAccount(holder, generator)); break; } case "platinum": { _storage?.AddBankAccount(account = new PlatinumAccount(holder, generator)); break; } case "gold": { _storage?.AddBankAccount(account = new GoldAccount(holder, generator)); break; } default: { throw new ArgumentException(nameof(accountType) + " is not defined."); } } return(account?.Id); }