/// <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);
        }
        /// <summary>
        /// Creates a bank account with passed user name, user surname, amount, type and id generator.
        /// and adds to the storage.
        /// </summary>
        /// <param name="userName">The user of bank account name.</param>
        /// <param name="userSurname">The user of bank account surname.</param>
        /// <param name="amount">The amount on the bank account.</param>
        /// <param name="generator">The generator of id.</param>
        /// <param name="type">The bank account type.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when <paramref name="userName"/>, <paramref name="userSurname"/>
        /// or/and <paramref name="generator"/> equal to null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown when the <paramref name="amount"/> less than 0.
        /// </exception>
        /// <exception cref="BankServiceException">
        /// Thrown when something wrong with adding the bank account to the storage.
        /// </exception>
        public void OpenBankAccount(string userName, string userSurname, decimal amount, IIDGenerator generator, AccountType type = AccountType.Base)
        {
            if (ReferenceEquals(userName, null))
            {
                throw new ArgumentNullException(nameof(userName));
            }

            if (ReferenceEquals(userSurname, null))
            {
                throw new ArgumentNullException(nameof(userSurname));
            }

            if (amount < 0)
            {
                throw new ArgumentException("The amount must be greater then or equal to 0.", nameof(amount));
            }

            if (ReferenceEquals(generator, null))
            {
                throw new ArgumentNullException(nameof(generator));
            }

            BankAccount newBankAccount = new BankAccount(generator.GetId(), userName, userSurname, amount, type);

            try
            {
                _bankAccountStorage.AddAccount(newBankAccount.ToAccount());
            }
            catch (AccountAlreadyExistsException ex)
            {
                throw new BankServiceException("An error occured while adding to the storage.", ex);
            }
        }
        /// <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);
            }
        }
Пример #4
0
    private IEnumerator RegisterAccount(string userName, int passwordHash, string data, Result <bool> result)
    {
        Result <bool> r = new Result <bool>(this);

        yield return(StartCoroutine(storage.AddAccount(userName, passwordHash, storage.GenerateAccountID(), data, r)));

        result.SetValue(r.Value);
    }
Пример #5
0
 public bool Register(string login, string password)
 {
     return(_storage.AddAccount(new Account
     {
         Id = Guid.NewGuid().ToString(),
         Login = login,
         Password = password
     }));
 }
Пример #6
0
        /// <summary>
        /// Adds a new account if it doesn't exist.
        /// </summary>
        public void AddBankAccount(BankAccount account)
        {
            CheckAccount(account);
            bool hasAccount = _storage.AccountExists(account);

            if (!hasAccount)
            {
                _storage.AddAccount(account);
            }
            else
            {
                throw new Exception("Our storage already has this account.");
            }
        }
Пример #7
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);
            }
        }