/// <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);
            }
        }
Exemple #2
0
        /// <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);
            }
        }
Exemple #3
0
 /// <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));
 }