Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created August 22, 2019 17:31
Show Gist options
  • Save dcomartin/5171076c2ef540fe63db8751fd4652bc to your computer and use it in GitHub Desktop.
Save dcomartin/5171076c2ef540fe63db8751fd4652bc to your computer and use it in GitHub Desktop.
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