private static void Main() { try { // Seam. IAccountRepository accountRepository = new BinaryFileAccountRepository(@"accounts.bin"); AccountIdService accountIdService = new GuidAccountIdService(); IAccountCreater accountCreater = new AccountCreater(); IAccountService accountService = new AccountService(accountRepository, accountIdService, accountCreater); if (File.Exists(@"accounts.bin")) { Test(accountService); } else { FileInitTests(accountService); } } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadLine(); }
/// <summary> /// Opening an account. /// </summary> /// <param name="type">Type of account.</param> /// <param name="firstName">First name of the owner.</param> /// <param name="lastName">Last name of the owner.</param> /// <param name="balance">Starting balance.</param> /// <exception cref="BankManagerException"> /// It is thrown out in case of problems in the service. /// </exception> /// <returns> /// If successful, it is true, otherwise false. /// </returns> public void OpenAccount(string firstName, string lastName, decimal balance, AccountType type = AccountType.BaseAccount) { if (string.IsNullOrEmpty(firstName)) { throw new System.ArgumentException(nameof(firstName)); } if (string.IsNullOrEmpty(lastName)) { throw new System.ArgumentException(nameof(lastName)); } BankAccount account = AccountCreater.CreateAccount(type, _numberGenerator.GenerateNumber(firstName, lastName, _accounts.Count), lastName, firstName, balance, 0); _accounts.Add(account); try { _accountStorage.AddAccount(account.ToAccountDal()); } catch (StorageException e) { _accounts.Remove(account); throw new BankManagerException("An error occurred while working with the repository.", e); } }
/// <summary> /// Opening an account. /// </summary> /// <param name="type">Type of account.</param> /// <param name="firstName">First name of the owner.</param> /// <param name="lastName">Last name of the owner.</param> /// <param name="balance">Starting balance.</param> /// <exception cref="BankManagerException"> /// It is thrown out in case of problems in the service. /// </exception> /// <returns> /// If successful, it is true, otherwise false. /// </returns> public void OpenAccount(string firstName, string lastName, decimal balance, AccountType type = AccountType.BaseAccount) { BankAccount account = AccountCreater.CreateAccount(type, GenerateNumber(), lastName, firstName, balance, 0); _accounts.Add(account); try { _accountStorage.AddAccount(account.ToAccountDal()); } catch (StorageException e) { _accounts.Remove(account); throw new BankManagerException("An error occurred while working with the repository.", e); } }
/// <summary> /// Converts data from the storage to service data /// </summary> /// <param name="accountDal"> Data from Dal</param> /// <returns> /// Data for the service. /// </returns> public static BankAccount ToAccount(this AccountDal accountDal) { return(AccountCreater.CreateAccount(accountDal.Type, accountDal.Number, accountDal.LastName, accountDal.FirstName, accountDal.Balance, accountDal.Bonus)); }