Example #1
0
        public string Transaction(DatabaseRepo _repo, int fromAccId, int toAccId, decimal amount)
        {
            var    accounts = _repo.AllAccounts();
            var    fromAcc  = accounts.FirstOrDefault(x => x.AccountId == fromAccId);
            var    toAcc    = accounts.FirstOrDefault(x => x.AccountId == toAccId);
            string result;

            if (CheckIfTransactionPossible(fromAcc, amount))
            {
                fromAcc.Balance -= amount;
                toAcc.Balance   += amount;
                _repo.CreateTransaction(new Transaction
                {
                    Amount        = amount,
                    FromAccountId = fromAccId,
                    ToAccountId   = toAccId
                });
                result = "Success";
            }
            else
            {
                result = "Lol you are too poor ";
            }
            return(result);
        }