示例#1
0
        private async Task SaveMemento(
            Guid sourceId,
            IMemento memento,
            CancellationToken cancellationToken)
        {
            using (IMementoStoreDbContext context = _dbContextFactory.Invoke())
            {
                Memento entity = await context
                                 .Mementoes
                                 .Where(m => m.AggregateId == sourceId)
                                 .SingleOrDefaultAsync(cancellationToken)
                                 .ConfigureAwait(false);

                if (entity == null)
                {
                    entity = new Memento {
                        AggregateId = sourceId
                    };
                    context.Mementoes.Add(entity);
                }

                entity.MementoJson = _serializer.Serialize(memento);

                await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
            }
        }
示例#2
0
        private async Task DeleteMemento(
            Guid sourceId,
            CancellationToken cancellationToken)
        {
            using (IMementoStoreDbContext context = _dbContextFactory.Invoke())
            {
                Memento entity = await context
                                 .Mementoes
                                 .Where(m => m.AggregateId == sourceId)
                                 .SingleOrDefaultAsync()
                                 .ConfigureAwait(false);

                if (entity == null)
                {
                    return;
                }

                context.Mementoes.Remove(entity);

                await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
            }
        }