public async Task AddSnapshotAsync(AddSnapshot model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } await _unitOfWork.CommitOrUndoAsync(async() => { await _validatorFactory.GetValidator <AddSnapshot>().ValidateAndThrowAsync(model); var stream = await _unitOfWork.StreamRepository.GetStreamByNameAsync(model.StreamName); if (stream == null) { throw new EntityNotFoundException($"Stream not found with name {model.StreamName}"); } var snapshot = new Repository.Entities.Snapshot { StreamId = stream.StreamId, Description = model.Description, Data = model.Data, Version = stream.Version }; await _unitOfWork.StreamRepository.AddSnapshotAsync(snapshot); }); }
public static Snapshot FromEntity(this Repository.Entities.Snapshot entity) => new Snapshot { Data = entity.Data, Version = entity.Version, Description = entity.Description, CreatedAt = entity.CreatedAt };