Created
August 22, 2019 17:31
-
-
Save dcomartin/5171076c2ef540fe63db8751fd4652bc 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 System; | |
using System.Threading.Tasks; | |
using Newtonsoft.Json; | |
using SqlStreamStore.Streams; | |
namespace SqlStreamStore.Demo | |
{ | |
public class Account | |
{ | |
private readonly StreamId _streamId; | |
private readonly IStreamStore _streamStore; | |
public Account(IStreamStore streamStore, StreamId streamId) | |
{ | |
_streamId = streamId; | |
_streamStore = streamStore; | |
} | |
public async Task<Guid> Deposit(decimal amount) | |
{ | |
var trx = Guid.NewGuid(); | |
var deposit = new Deposited(trx, amount, DateTime.UtcNow); | |
await _streamStore.AppendToStream(_streamId, ExpectedVersion.Any, new NewStreamMessage(trx, "Deposited", JsonConvert.SerializeObject(deposit))); | |
return trx; | |
} | |
public async Task<Guid> Withdrawal(decimal amount) | |
{ | |
var trx = Guid.NewGuid(); | |
var deposit = new Withdrawn(trx,amount, DateTime.UtcNow); | |
await _streamStore.AppendToStream(_streamId, ExpectedVersion.Any, new NewStreamMessage(trx, "Withdrawn", JsonConvert.SerializeObject(deposit))); | |
return trx; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment