Last active
May 25, 2020 08:08
-
-
Save ayende/3a2d844d54b763875c36a5cae88fe357 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
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