public string OpenAccount(string name, AccountType accountType, IAccountNumberCreator creator) { Account account = null; string accountNumber = creator.Create(); Account accountInList = accounts?.Find(a => a.AccountNumber == accountNumber); while (accountInList != null) { accountNumber = creator.Create(); accountInList = accounts?.Find(a => a.AccountNumber == accountNumber); } switch (accountType) { case AccountType.Base: account = new BaseAccount(accountNumber, name); break; case AccountType.Gold: account = new GoldAccount(accountNumber, name); break; case AccountType.Platinum: account = new PlatinumAccount(accountNumber, name); break; } if (accounts == null) { return(accountNumber); } accounts.Add(account); repository.Save(accounts); return(accountNumber); }
static void Main(string[] args) { IAccountService service = resolver.Get <IAccountService>(); IAccountNumberCreator creator = resolver.Get <IAccountNumberCreator>(); service.CreateAccount("1", "1", AccountType.Base, creator); service.CreateAccount("2", "2", AccountType.Gold, creator); service.CreateAccount("3", "3", AccountType.Base, creator); service.CreateAccount("4", "4", AccountType.Platinum, creator); service.Save(); IAccountService service2 = resolver.Get <IAccountService>(); service2.Load(); BankAccount account = service2.GetAccountByAccountNumber(2); account.Deposit(100); Console.WriteLine(account.ToString()); }
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); }
public void CreateAccount(string fname, string lname, AccountType type, IAccountNumberCreator creator) { var account = AccountFactory.Create(fname, lname, type, creator.CreateNumber()); _accounts.Add(account); }