Ejemplo n.º 1
0
        public void Save(DomainEvent domainEvent)
        {
            using (var session = _documentStore.OpenSession())
            {
                MatchHistory history = session.Load <MatchHistory>(domainEvent.SagaId);
                if (history == null)
                {
                    history = new MatchHistory(domainEvent.SagaId);
                    session.Store(history);
                }

                var eventWrapper = new EventWrapper(domainEvent);
                session.Store(eventWrapper);
                string key = session.Advanced.GetDocumentId(eventWrapper);
                history.Records.Add(key);

                session.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public void UndoLastAction(String matchId)
        {
            using (var session = _documentStore.OpenSession())
            {
                MatchHistory matchHistory = session.Load <MatchHistory>(matchId);
                if (matchHistory == null)
                {
                    return;
                }

                EventWrapper lastEvent = session.Load <EventWrapper>(matchHistory.Records).LastOrDefault();
                if (lastEvent == null)
                {
                    return;
                }

                string key = session.Advanced.GetDocumentId(lastEvent);
                session.Delete(lastEvent);
                matchHistory.Records.Remove(key);

                session.SaveChanges();
            }
        }