public async Task <bool> UpdateAccounts(UpdateAccounts message) { bool areAccountsExist = await _accountNSBRepository .CheckAccountsCorrectness(message.FromAccountId, message.ToAccountId); if (areAccountsExist == false) { return(false); } bool isBalanceEnough = await _accountNSBRepository .CheckBalance(message.FromAccountId, message.Amount); if (isBalanceEnough == false) { return(false); } return(await _accountNSBRepository.UpdateAccounts(message)); }
public async Task <bool> UpdateAccounts(UpdateAccounts message) { try { var fromAccount = await _accountContext.Accounts .FirstOrDefaultAsync(account => account.Id == message.FromAccountId); fromAccount.Balance -= message.Amount; var toAccount = await _accountContext.Accounts .FirstOrDefaultAsync(account => account.Id == message.ToAccountId); toAccount.Balance += message.Amount; await _accountContext.SaveChangesAsync(); return(true); } catch { throw new SystemException(); } }