public async Task TakeAndSaveAsync(IAggregateRoot aggregate) { var snapshot = aggregate.ToSnapshot(); string insertScript = EventRepositoryScriptsAsStrings.InsertSnapshot(); await _databaseProvider.ExecuteAsync(insertScript, snapshot); Log.Information($"Snapshot for aggregate {aggregate.GetType().Name} has been created from version {aggregate.Version}"); }
public async Task SaveAsync <T>(IEnumerable <IEvent> events, Guid aggregateId, int originalVersion) { var validator = ValidateVersionAsync <T>(aggregateId, originalVersion); var aggregateType = typeof(T).Name; var eventsToSave = events.Select(e => e.ToEventData(aggregateId, aggregateType, originalVersion++, DateTime.Now)); string insertScript = EventRepositoryScriptsAsStrings.InsertIntoAggregate(aggregateType); await validator; await _databaseProvider.ExecuteAsync(insertScript, eventsToSave); Log.Information($"Events for aggregate {aggregateType} with Id {aggregateId} has been saved."); }