Created
March 4, 2020 07:20
-
-
Save ayende/6b2ff704ec56f6268d5dbf136fdf1c4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task SendMoney(SendMoneyRequest req) | |
{ | |
var srcAccount = await _accountRepository.LoadAsync(req.SourceAccount); | |
var dstAccount = await _accountRepository.LoadAsync(req.DesinationAccount); | |
Guard.Null(srcAccount, "Source account must exists"); | |
Guard.Null(dstAccount, "Destination account must exists"); | |
var rules = _transferValidationRules.GetAll(); | |
var state = new TranfserValidationState(); | |
foreach(var rule in rules) | |
{ | |
await rule.Prepare(req, state); | |
} | |
await state.LoadEverything(); | |
foreach(var rule in rules) | |
{ | |
await rule.Validate(req, state); | |
} | |
srcAccount.TransferFunds(dstAccount, req.Amount); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment