Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.