Exemple #1
0
        public async Task Handle(BookReadSavedEvent request, CancellationToken cancellationToken)
        {
            BookFileSavedEvent eventData;

            using (var transaction = new TransactionScope())
            {
                var savedBook = bookFileStorage.Save(request.Book);
                eventData = new BookFileSavedEvent(request.Id, savedBook);
                bookSagaEventRepository.Add(ConvertEvent(eventData));
                transaction.Complete();
            }
            await mediator.Publish(eventData);
        }
Exemple #2
0
        public async Task Handle(BookCreatedEvent request, CancellationToken cancellationToken)
        {
            var eventData = new BookReadSavedEvent(request.Id, request.Book);

            using (var transaction = new TransactionScope())
            {
                bookReadRepository.Add(new Book
                {
                    Id     = request.Id,
                    Author = request.Book.Author,
                    Title  = request.Book.Title,
                    Status = request.Status
                });
                bookSagaEventRepository.Add(ConvertEvent(eventData));
                transaction.Complete();
            }
            await mediator.Publish(eventData);
        }