public async Task <AppResponse> Handle(TCommand request, CancellationToken cancellationToken) { return(await Task.Factory.StartNew(() => { Exception = new TransactionFailedException(); var fromErrorCode = From.DecreaseBalance(request.Amount, request.TransactionId); CheckDecreaseBalanceResult(fromErrorCode, request); var toErrorCode = To.IncreaseBalance(request.Amount, request.TransactionId); CheckIncreaseBalanceResult(toErrorCode, request); return AppResponse.Success(null); })); }
private void StartTransaction() { double fromAmount = Amount, toAmount = Amount; if (From.Currency != Currency || To.Currency != Currency) { if (From.Currency != Currency) { fromAmount = CurrencyTools.Convert(Amount, From.Currency, Currency); } if (To.Currency != Currency) { toAmount = CurrencyTools.Convert(Amount, To.Currency, Currency); } } From.DecreaseBalance(fromAmount); To.IncreaseBalance(toAmount); }