private static void Main(string[] args) { IAccountService service = Resolver.Get <IAccountService>(); IAccountNumberCreateService creator = Resolver.Get <IAccountNumberCreateService>(); service.OpenAccount("Don Milon", CardType.Base, creator); service.OpenAccount("Ken Down", CardType.Base, creator); service.OpenAccount("Lick Shane", CardType.Gold, creator); service.OpenAccount("Rita McGrey", CardType.Base, creator); var creditNumbers = service.GetAllAccounts().Select(acc => acc.AccountNumber).ToArray(); foreach (var t in creditNumbers) { service.DepositAccount(t, 100); } foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item); } foreach (var t in creditNumbers) { service.WithdrawAccount(t, 10); } foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item); } Console.Read(); }
static void Main(string[] args) { IAccountService service = resolver.Get <IAccountService>(); IAccountNumberCreateService creator = resolver.Get <IAccountNumberCreateService>(); service.OpenAccount("Account owner 1", "email1", AccountType.Base, creator); service.OpenAccount("Account owner 2", "email2", AccountType.Base, creator); service.OpenAccount("Account owner 3", "email3", AccountType.Base, creator); //var creditNumbers = service.GetAllAccounts().Select(acc => acc.Number).ToArray(); //foreach (var t in creditNumbers) //{ // service.DepositAccount(t, 100); //} foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item); } //foreach (var t in creditNumbers) //{ // service.WithdrawAccount(t, 10); //} //foreach (var item in service.GetAllAccounts()) //{ // Console.WriteLine(item); //} }
/// <summary> /// Method creates new account with given parameters and saves data to storage. /// </summary> /// <param name="accountOwner"> /// Account owner - required data to create account. /// </param> /// <param name="type"> /// Account type - required data to create account. /// </param> /// <param name="creator"> /// Account number generation strategy injected as method argument. /// </param> public void OpenAccount(string accountOwner, AccountType type, IAccountNumberCreateService creator) { Account newAccount = AccountMapper.CreateAccount(type, creator.GenerateAccountNumber(AccountDTO.id), accountOwner, 0, 0); AccountDTO.id++; this.repository.Create(newAccount.ToAccountDTO()); }
//private static readonly IMailService GmailService; static Program() { Kernel = new StandardKernel(); NInjectDependencyResolver.Configure(Kernel); AccountNumberCreateService = Kernel.Get <IAccountNumberCreateService>(); // GmailService = Kernel.Get<IMailService>(); }
public static void Main(string[] args) { IAccountService service = Resolver.Get <IAccountService>(); IAccountNumberCreateService creator = Resolver.Get <IAccountNumberCreateService>(); service.OpenAccount("Base acc owner 1", AccountType.Base, creator); service.OpenAccount("Silver acc owner 2", AccountType.Silver, creator); service.OpenAccount("Gold acc owner 3", AccountType.Gold, creator); service.OpenAccount("Platinum acc owner 4", AccountType.Platinum, creator); var creditNumbers = service.GetAllAccounts().Select(acc => acc.AccountNumber).ToArray(); foreach (var t in creditNumbers) { service.DepositAccount(t, 100); } foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item); Console.WriteLine(); } foreach (var t in creditNumbers) { service.WithdrawAccount(t, 10); } foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item); Console.WriteLine(); var qwe = AccountMapper.ConvertToDTO(item); } }
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); }
private static void Main(string[] args) { IAccountService service = _Resolver.Get <IAccountService>(); IAccountNumberCreateService creator = _Resolver.Get <IAccountNumberCreateService>(); service.OpenAccount("owner", "Account owner 1", AccountType.Gold, creator); service.OpenAccount("owner", "Account owner 2", AccountType.Base, creator); service.OpenAccount("owner", "Account owner 3", AccountType.Silver, creator); service.OpenAccount("owner", "Account owner 4", AccountType.Base, creator); var accounts = service.GetAllAccounts(); foreach (var t in accounts) { service.DepositAccount(t, 100); } foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item); } foreach (var t in accounts) { service.WithdrawAccount(t, 10); } foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item); } Console.ReadLine(); }
/// <summary> /// Initializes serice with some entities. /// </summary> /// <param name="service">Service for initializing.</param> /// <param name="creator">Account ID creator.</param> private static void InitService(IAccountService service, IAccountNumberCreateService creator) { service.OpenAccount("Account owner 1", AccountType.Base, new BaseAccountBonus(), creator); service.OpenAccount("Account owner 2", AccountType.Base, new BaseAccountBonus(), creator); service.OpenAccount("Account owner 3", AccountType.Silver, new ExtraAccountBonus(), creator); service.OpenAccount("Account owner 4", AccountType.Base, new BaseAccountBonus(), creator); }
/// <summary> /// Starts the program. /// </summary> public static void Main() { IAccountService service = Resolver.Get <IAccountService>(); IAccountNumberCreateService creator = Resolver.Get <IAccountNumberCreateService>(); // InitService(service, creator); var creditNumbers = service.GetAllAccounts().Select(acc => acc.AccountNumber).ToArray(); foreach (var t in creditNumbers) { service.DepositAccount(t, 100); } foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item); } foreach (var t in creditNumbers) { service.WithdrawAccount(t, 10); } foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item); } }
static void Main(string[] args) { IAccountService service = resolver.Get <IAccountService>(); IAccountNumberCreateService creator = resolver.Get <IAccountNumberCreateService>(); service.OpenAccount("Account owner 1", AccountType.Base, creator); service.OpenAccount("Account owner 2", AccountType.Base, creator); service.OpenAccount("Account owner 3", AccountType.Silver, creator); service.OpenAccount("Account owner 4", AccountType.Base, creator); var creditNumbers = service.GetAllAccounts().Select(acc => acc.AccountNumber).ToArray(); foreach (var t in creditNumbers) { service.DepositAccount(t, 100); } foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item); } foreach (var t in creditNumbers) { service.WithdrawAccount(t, 10); } foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item); } Console.ReadLine(); }
/// <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 AccountsController() { IKernel ninjectKernel = new StandardKernel(); ninjectKernel.ConfigurateResolver(); _service = ninjectKernel.Get <IAccountService>(); _creator = ninjectKernel.Get <IAccountNumberCreateService>(); }
//TODO Make interface for logger //private Logger logger; #endregion #region Constructors public AccountService(IRepository <DalAccount> accounts, IRepository <DalHolder> holders, IAccountNumberCreateService givenGenerator) { accountsRepository = accounts; holdersRepository = holders; numberGenerator = givenGenerator; //logger = LogManager.GetLogger("BankServiceLogger"); //logger.Info("Service were created!"); }
/// <summary> /// Constructor for Account service /// </summary> /// <param name="accountRepository">repository for work with entity Account</param> /// <param name="userService">service for work with entity User</param> /// <param name="creator">service for create number account</param> public AccountService(IAccountRepository accountRepository, IUserService userService, IAccountNumberCreateService creator) { this.accountRepository = accountRepository; this.userService = userService; this.creator = creator; }
public string OpenAccount(AccountType accountType, IAccountNumberCreateService creator, string ownerName, string ownerEmail, decimal balance = 0m, int benefitPoints = 0) { string accountNumber = creator.Create(GetNumberOfAccounts()); var account = CreateAccountType(accountNumber, accountType, ownerName, ownerEmail, balance, benefitPoints); repository.Create(account.ToDalAccount()); unitOfWork.Commit(); return(accountNumber); }
static void Main(string[] args) { IAccountService service = resolver.Get <IAccountService>(); IAccountNumberCreateService creator = resolver.Get <IAccountNumberCreateService>(); //IRepository<DalAccount> accounts = new AccountRepository(); //IRepository<DalHolder> holders = new HolderRepository(); //IAccountService service = new AccountService(accounts, holders, new AccountNumberGenerator()); while (true) { PrintMenu(); ConsoleKeyInfo choose = Console.ReadKey(); if (choose.KeyChar == '1') { service.OpenAccount(InputAccountData()); } else if (choose.KeyChar == '2') { Console.WriteLine(); foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item.AccountNumber + " | " + item.Balance + " | " + item.AccountHolder.Name); } Console.WriteLine(); } else if (choose.KeyChar == '3') { Console.WriteLine(); service.Withdraw( Console.ReadLine(), decimal.Parse(Console.ReadLine())); } else if (choose.KeyChar == '4') { Console.WriteLine(); service.Deposit( Console.ReadLine(), decimal.Parse(Console.ReadLine())); } else if (choose.KeyChar == '5') { Console.WriteLine("Soon..."); } } }
/// <summary> /// Create instance on AccountType information, userInfo and IAccountNumberCreateService /// </summary> /// <param name="type">AccountType type</param> /// <param name="userId">id user</param> /// <param name="creator">IAccountNumberCreateService instance</param> /// <returns>new instance Account</returns> public static Account Create(AccountType type, int userId, IAccountNumberCreateService creator) { switch (type) { case AccountType.Base: return(new BaseAccount(userId, creator)); case AccountType.Silver: return(new SilverAccount(userId, creator)); case AccountType.Gold: return(new GoldAccount(userId, creator)); case AccountType.Platinum: return(new PlatinumAccount(userId, creator)); default: throw new InvalidOperationException($"Unknown type {type} for create account"); } }
/// <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 void Main(string[] args) { IAccountService service = Resolver.Get <IAccountService>(); IAccountNumberCreateService creator = Resolver.Get <IAccountNumberCreateService>(); service.OpenAccount("Account owner 1", AccountType.Base, creator); service.OpenAccount("Account owner 2", AccountType.Base, creator); service.OpenAccount("Account owner 3", AccountType.Silver, creator); service.OpenAccount("Account owner 4", AccountType.Base, creator); var creditNumbers = service.GetAllAccounts().Select(acc => acc.AccountNumber).ToArray(); foreach (var t in creditNumbers) { service.DepositAccount(t, 100); } foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item); } foreach (var t in creditNumbers) { service.WithdrawAccount(t, 10); } foreach (var item in service.GetAllAccounts()) { Console.WriteLine(item.Balls); } using (var db = new DatabaseRepository()) { service.GetAllAccounts().ForEach((acc) => db.accounts.Add(acc)); db.SaveChanges(); } Console.WriteLine("Clear!"); Console.ReadKey(); }
public void OpenAccount(string ownerName, string accountType, IAccountNumberCreateService numberCreator) { if (string.IsNullOrEmpty(ownerName)) { throw new ArgumentException("Argument is null or empty", nameof(ownerName)); } if (numberCreator is null) { throw new ArgumentNullException(nameof(numberCreator)); } var account = accountFactory.GetInstance(accountType); account.AccountNumber = numberCreator.GetNextNumber(); account.Owner = new AccountOwner() { FirstName = ownerName }; account.Status = AccountStatus.Active; repository.Create(account.ToAccountDto()); }
public HomeController(IAccountService service, IAccountNumberCreateService accountNumberService) { _service = service; _numberService = accountNumberService; }
/// <summary> /// Create new account /// </summary> /// <param name="account"></param> public void OpenAccount(string owner, CardType type, IAccountNumberCreateService id) { Account acc = new Account(id.GenerateId(GetNumberOfAccounts() + 1), owner, type); repo.Create(AccountMapper.Mapper.Map <AccountDTO>(acc)); }
static void Main(string[] args) { IAccountService accountService = resolver.Get <IAccountService>(); IUserService userService = resolver.Get <IUserService>(); IAccountNumberCreateService creator = resolver.Get <IAccountNumberCreateService>(); Console.WriteLine("All accounts in database"); Console.WriteLine(); foreach (var item in accountService.GetAll()) { Console.WriteLine(item); } Console.WriteLine(); try { #region Test add new account var personFirst = userService.Create("Fedor", "Bondarchuk", "RT1234134", "*****@*****.**"); accountService.OpenAccount("Base", personFirst.Id); accountService.OpenAccount("Silver", personFirst.Id); accountService.OpenAccount("Gold", personFirst.Id); accountService.OpenAccount("Platinum", personFirst.Id); var personSecond = userService.Create("Fedor", "Volkov", "RT1234134", "*****@*****.**"); accountService.OpenAccount("Base", personSecond.Id); accountService.OpenAccount("Silver", personSecond.Id); accountService.OpenAccount("Gold", personSecond.Id); accountService.OpenAccount("Platinum", personSecond.Id); Console.WriteLine("After add in collection"); Console.WriteLine(); foreach (var item in accountService.GetAll()) { Console.WriteLine(item); } #endregion #region Test deposit and withdraw var account = accountService.GetByNumber("40512100790000000004"); Console.WriteLine($"Befor withdraw Balance : {account.Balance}, BenefitPoints : {account.BenefitPoints}"); accountService.WithDrawAccount(account.NumberOfAccount, 100); account = accountService.GetByNumber("40512100790000000004"); Console.WriteLine($"After withdraw 100 Balance : {account.Balance}, BenefitPoints : {account.BenefitPoints}"); accountService.DepositAccount(account.NumberOfAccount, 200); account = accountService.GetByNumber("40512100790000000004"); Console.WriteLine($"After deposite 200 Balance : {account.Balance}, BenefitPoints : {account.BenefitPoints}"); #endregion #region Test transfer var accountWithDrawTransfer = accountService.GetByNumber("40512100790000000003"); var accountDepositTransfer = accountService.GetByNumber("40512100790000000004"); Console.WriteLine($"Before transfer balance account for withdraw {accountWithDrawTransfer.Balance}" + $"account for deposit {accountDepositTransfer.Balance}"); var resultTransfer = accountService.Transfer(accountWithDrawTransfer.NumberOfAccount, accountDepositTransfer.NumberOfAccount, 50); Console.WriteLine($"After transfer balance account for withdraw {resultTransfer.Item1.Balance}" + $"account for deposit {resultTransfer.Item2.Balance}"); #endregion } catch (Exception e) { Console.WriteLine(e.Message); } }
public AccountController() { accountService = Utils.DependencyResolver.AccountService; accountNumberCreator = Utils.DependencyResolver.AccountNumberCreator; mailService = Utils.DependencyResolver.GmailService; }
/// <summary> /// Initializes a new instance of the <see cref="BankAccountService"/> class. /// </summary> public BankAccountService() { this.bankAccounts = new FakeStorage(); this.numberCreateService = new AccountNumberCreate(); }
/// <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> /// Opens new bank account /// </summary> /// <param name="firstName">Owner's first name</param> /// <param name="lastName">Owner's last name</param> /// <param name="accountType">Type of account</param> /// <param name="accountNumberCreator">Given account number generator</param> public void OpenAccount(string firstName, string lastName, AccountType accountType, IAccountNumberCreateService accountNumberCreator) { int id = accountNumberCreator.GenerateNumber(Max); _repository.AddAccount(new BankAccountDTO(id, firstName, lastName, 0.0m, 0, accountType.ToString())); }
internal BaseAccount(int userId, IAccountNumberCreateService creator) : base(userId, creator) { }
/// <summary> /// Create instance account /// </summary> internal Account(int userId, IAccountNumberCreateService creator) { this.userId = userId; this.numberOfAccount = creator.GetNumberAccount(); }