public async ValueTask <BookImportResult> ImportBookAsync(BookId bookId) { var book = await _bookStore.FindBookAsync(bookId) .ConfigureAwait(false); if (book == null) { throw new InvalidOperationException($"Book {bookId} is not found."); } var bookContent = await _bookStore.FindBookContentAsync(bookId) .ConfigureAwait(false); if (bookContent == null) { throw new InvalidOperationException($"Content for the book {bookId} is not found."); } book.StartProcessing(); await _bookStore.UpdateBookAsync(book) .ConfigureAwait(false); await _sentenceRepository.RemoveAllForBook(bookId) .ConfigureAwait(false); // TODO: Everything below is not unit tested yet. try { var result = await ImportBookAsync(book, bookContent) .ConfigureAwait(false); book.FinishProcessing(); await _bookStore.UpdateBookAsync(book) .ConfigureAwait(false); return(result); } catch (Exception exception) { _logger.LogError(exception, "Error while importing the book {BookId}.", bookId.Value); book.ErrorProcessing(); await _bookStore.UpdateBookAsync(book) .ConfigureAwait(false); throw new InvalidOperationException($"Error while importing book {bookId}"); } }
public async ValueTask ArchiveBookAsync(BookId bookId) { var book = await _bookRepository.FindBookAsync(bookId) .ConfigureAwait(false); if (book == null) { throw new InvalidOperationException("Book doesn't exist."); } book.Archive(); await _bookRepository.UpdateBookAsync(book) .ConfigureAwait(false); await _sentenceRepository.RemoveAllForBook(bookId) .ConfigureAwait(false); }