Example #1
0
        /// <summary>
        /// Withdraws from a bank account
        /// </summary>
        /// <param name="account">Bank account to withdraw</param>
        /// <param name="withdrawal">Given withdrawal amount</param>
        public void WithdrawAccount(BankAccount account, decimal withdrawal)
        {
            account.Withdraw(withdrawal);
            BankAccountDTO accToUpdate = BankAccountMapper.BankAccToDTO(account);

            _repository.UpdateAccount(accToUpdate);
        }
        /// <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 OpenAccount(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(BankAccountMapper.ToDTO(account));

            return(account.IBAN);
        }
Example #3
0
        /// <summary>
        /// Deposits into a bank account
        /// </summary>
        /// <param name="account">Bank account to deposit</param>
        /// <param name="deposit">Given deposit amount</param>
        public void DepositAccount(BankAccount account, decimal deposit)
        {
            account.Deposit(deposit);
            BankAccountDTO accToUpdate = BankAccountMapper.BankAccToDTO(account);

            _repository.UpdateAccount(accToUpdate);
        }
        /// <summary>
        /// Makes a withdrawal of <paramref name="amount"/> from an account with specified <paramref name="iban"/>
        /// </summary>
        /// <param name="iban">IBAN of an account to make withdrawal</param>
        /// <param name="amount">withdrawal amount</param>
        /// <returns>new account balance</returns>
        /// <exception cref="ArgumentException">withdrawal amount is lesser than minimal</exception>
        public decimal MakeWithdrawal(string iban, decimal amount)
        {
            if (string.IsNullOrWhiteSpace(iban))
            {
                throw new ArgumentException("No IBAN is given.", "IBAN");
            }

            if (amount < MINWITHDRAWAL)
            {
                throw new ArgumentException("Minimum withdrawal amount is " + MINWITHDRAWAL.ToString("C"));
            }



            var account = BankAccountMapper.FromDTO(Storage.GetAccount(iban));

            if (amount > account.Balance)
            {
                throw new InvalidOperationException("account balance is less than withdrawal amount");
            }

            account.Balance     -= amount;
            account.BonusPoints -= BonusCalculator.CalculateWithdrawalBonus(account, amount);
            Storage.UpdateAccount(BankAccountMapper.ToDTO(account));

            return(account.Balance);
        }
Example #5
0
        /// <summary>
        /// Getss all bank accounts in the repository
        /// </summary>
        /// <returns>Collection of all bank accounts in the repository</returns>
        public IEnumerable <BankAccount> GetAllAccounts()
        {
            var accounts = _repository.GetAll();

            foreach (var acc in accounts)
            {
                yield return(BankAccountMapper.DTOToBancAcc(acc));
            }
        }
Example #6
0
        /// <summary>
        /// Gets account by its id
        /// </summary>
        /// <param name="id">Given id</param>
        /// <returns>Bank account with given id</returns>
        public BankAccount GetAccountById(int id)
        {
            var accounts = _repository.GetAll();

            foreach (var acc in accounts)
            {
                if (acc.Id == id)
                {
                    return(BankAccountMapper.DTOToBancAcc(acc));
                }
            }

            return(null);
        }
        /// <summary>
        /// Makes a deposit of <paramref name="amount"/> to an account with specified <paramref name="iban"/>.
        /// </summary>
        /// <param name="iban">IBAN of an account to make deposit</param>
        /// <param name="amount">deposit amount</param>
        /// <returns>new account balance</returns>
        /// <exception cref="ArgumentException">deposit amount is lesser than minimal</exception>
        public decimal MakeDeposit(string iban, decimal amount)
        {
            if (string.IsNullOrWhiteSpace(iban))
            {
                throw new ArgumentException("No IBAN is given.", "IBAN");
            }

            if (amount < MINDEPOSIT)
            {
                throw new ArgumentException("Minimum deposit amount is " + MINDEPOSIT.ToString("C"));
            }

            var account = BankAccountMapper.FromDTO(Storage.GetAccount(iban));

            account.Balance     += amount;
            account.BonusPoints += BonusCalculator.CalculateDepositBonus(account, amount);
            Storage.UpdateAccount(BankAccountMapper.ToDTO(account));

            return(account.Balance);
        }
Example #8
0
        /// <summary>
        /// Closes bank account
        /// </summary>
        /// <param name="account">Bank account to close</param>
        public void CloseAcount(BankAccount account)
        {
            BankAccountDTO accToRemove = BankAccountMapper.BankAccToDTO(account);

            _repository.RemoveAccount(accToRemove);
        }