Skip to content

Instantly share code, notes, and snippets.

@ayende
Last active May 25, 2020 08:08
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/3a2d844d54b763875c36a5cae88fe357 to your computer and use it in GitHub Desktop.
Save ayende/3a2d844d54b763875c36a5cae88fe357 to your computer and use it in GitHub Desktop.
using (var session = store.OpenAsyncSession())
{
var src = await session.LoadAsync<Account>("accounts/123-A");
var dst = await session.LoadAsync<Account>("accounts/456-B");
if(src.Blocked || dst.Blocked)
throw new InvalidOperationException("Unable to transfer money from/to blocked accounts");
if(src.Funds < 5)
throw new InvalidOperationException("Insufficient funds");
var coins = src.WithdrawCoins(amount);
if (coins.Any(coin => coin.Tainted))
{
throw new InvalidOperationException("Unable to use tainted coins");
}
dst.AddCoins(coins);
await session.SaveChangesAsync();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment