Skip to content

Instantly share code, notes, and snippets.

@ayende
Created March 4, 2020 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayende/6b2ff704ec56f6268d5dbf136fdf1c4b to your computer and use it in GitHub Desktop.
Save ayende/6b2ff704ec56f6268d5dbf136fdf1c4b to your computer and use it in GitHub Desktop.
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