Skip to content

Instantly share code, notes, and snippets.

@ayende
Created March 4, 2020 07:14
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/0eabfa54997a889b79044393b2771c76 to your computer and use it in GitHub Desktop.
Save ayende/0eabfa54997a889b79044393b2771c76 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();
foreach(var rule in rules)
{
await rule.Validate(req);
}
srcAccount.TransferFunds(dstAccount, req.Amount);
}
public class MoneyTransferValidationRules : IMoneyTransferValidationRules
{
public ValidateTransferRule GetAll()
{
yield return new SourceAccountIsValid();
yield return new SourceAccountHasFunds();
yield return new SourceAccountDailyLimitNotExceed();
// .. many more ..
yield return new DestinationAccountHasNoLiens();
yield return new DestinationAccountMaxAmountNotExceeded();
// .. and more ...
yield return new MoneyTransferIsNotFromDirtyBitcoins();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment