public bool ExternalTransfer(int dest, decimal amount, string notes) { var ret = false; Raise.ArgumentException.IfNot(AccountExists(dest), "", "Invalid account mentioned"); Raise.ArgumentException.If(amount == 0.0M, "", "Amount cannot be empty"); var account = _context.Accounts.FirstOrDefault(x => x.AccountNo == dest); if (amount < 0.0M && Math.Abs(amount) <= account.Balance) { //Withdrawn var trx = new Domain.Transaction { TransactionId = _context.TransactionId(), SourceNo = dest, AccountSource = account, TargetNo = null, AccountTarget = null, Amount = amount, PostedOn = DateTime.Now, Notes = notes }; account.Balance -= amount; _context.Transactions.Add(trx); } else { //Deposit var trx = new Domain.Transaction { TransactionId = _context.TransactionId(), TargetNo = dest, AccountTarget = account, SourceNo = null, AccountSource = null, Amount = amount, PostedOn = DateTime.Now, Notes = notes }; account.Balance += amount; _context.Transactions.Add(trx); } _context.SaveChanges(); ret = true; _log.Info($"{(amount > 0.0M ? "debit" : "credit")} has been made into {account.AccountName}: {account.AccountNo}"); return(ret); }