Exemplo n.º 1
0
 public async Task InitATM()
 {
     await _aTMRepository.CreateAsync(new BankTransaction()
     {
         Amount = 10000, ATMAddress = "Prospekt Nauki 37", IsDebit = true, TransactionDate = DateTime.Now
     });
 }
Exemplo n.º 2
0
        public async Task Withdraw(int amount, string address)
        {
            if (amount <= 0)
            {
                throw new ATMRateEqualZeroException("Amount cant be less or equals then zero");
            }
            if (amount % 5 > 0)
            {
                throw new ATMNotEnoughMoneyException("Amount is incorrect");
            }
            if (string.IsNullOrWhiteSpace(address))
            {
                throw new ATMNotEnoughMoneyException("Address is incorrect");
            }

            var totalAmount = _aTMRepository.All.Sum(x => x.Amount);

            if (totalAmount < amount)
            {
                throw new ATMNotEnoughMoneyException("Not enough money");
            }
            await _aTMRepository.CreateAsync(new BankTransaction()
            {
                Amount = -amount, ATMAddress = address, IsDebit = false, TransactionDate = DateTime.Now
            });
        }