public BankAccount GetByID(int accountNo) { var account = _bankAccountRepository.FindByID(accountNo); //var account = AutoMapper.Mapper.Map<BankAccountDto, BankAccount>(accountDto); return(account); }
public TransactionDto CreateDeposit(int accountNo, decimal amount, string currencyID) { var bankAccount = _bankAccountRepository.FindByID(accountNo); if (bankAccount is null) { throw new InValidAccountNoException("Your account number does not exist!"); } if (amount <= 0) { throw new InValidAmountException("Your deposit amount cannot be equal to or less than 0!"); } if (currencyID.Length < 3) { throw new InValidAmountException("Your currency is not in correct format. Pass your currencyID!"); } var transactionCurrencyDto = _currencyRepository.FindByID(currencyID); if (transactionCurrencyDto is null) { throw new InValidCurrencyIDException("Your currency ID does not exist!"); } var accountExchangeRate = _currencyRepository.FindByID(bankAccount.CurrencyID).ExchangeRate; var currency = AutoMapper.Mapper.Map <CurrencyDto, Currency>(transactionCurrencyDto); //var bankAccount = AutoMapper.Mapper.Map<BankAccountDto, BankAccount>(bankAccountDto); bankAccount.Deposit(accountNo, amount, currency, accountExchangeRate); var transactionDto = new TransactionDto(); try { transactionDto = _transactionRepository.Add(bankAccount.Transactions.Last().TransactionID); } catch (Exception ex) { throw new Exception($"Something went wrong while processing your deposit. Try again later! {ex.Message}"); } return(transactionDto); }