public override async Task <UpdateBookContentRequest> HandleAsync(UpdateBookContentRequest command, CancellationToken cancellationToken = new CancellationToken())
        {
            var book = await _bookRepository.GetBookById(command.LibraryId, command.BookId, command.AccountId, cancellationToken);

            if (book != null)
            {
                var bookContent = await _bookRepository.GetBookContent(command.LibraryId, command.BookId, command.Language, command.MimeType, cancellationToken);

                if (bookContent != null)
                {
                    if (!string.IsNullOrWhiteSpace(bookContent.ContentUrl))
                    {
                        await _fileStorage.TryDeleteFile(bookContent.ContentUrl, cancellationToken);
                    }

                    var url = await StoreFile(command.BookId, command.Content.FileName, command.Content.Contents, cancellationToken);

                    bookContent.ContentUrl = url;
                    await _bookRepository.UpdateBookContentUrl(command.LibraryId,
                                                               command.BookId,
                                                               command.Language,
                                                               command.MimeType,
                                                               url, cancellationToken);

                    command.Result.Content = bookContent;
                }
                else
                {
                    var url = await StoreFile(command.BookId, command.Content.FileName, command.Content.Contents, cancellationToken);

                    command.Content.FilePath = url;
                    command.Content.IsPublic = book.IsPublic;
                    var file = await _fileRepository.AddFile(command.Content, cancellationToken);

                    await _bookRepository.AddBookContent(command.BookId, file.Id, command.Language, command.MimeType, cancellationToken);

                    command.Result.HasAddedNew = true;
                    command.Result.Content     = await _bookRepository.GetBookContent(command.LibraryId, command.BookId, command.Language, command.MimeType, cancellationToken);;
                }
            }

            return(await base.HandleAsync(command, cancellationToken));
        }
        public override async Task <AddBookContentRequest> HandleAsync(AddBookContentRequest command, CancellationToken cancellationToken = new CancellationToken())
        {
            var book = await _bookRepository.GetBookById(command.LibraryId, command.BookId, command.AccountId, cancellationToken);

            if (book != null)
            {
                var status = (await _bookRepository.GetBookPageSummary(command.LibraryId, new[] { book.Id }, cancellationToken)).FirstOrDefault();

                if (status != null)
                {
                    book.PageStatus = status.Statuses;
                    if (status.Statuses.Any(s => s.Status == EditingStatus.Completed))
                    {
                        decimal completedPages = (decimal)status.Statuses.Single(s => s.Status == EditingStatus.Completed).Count;
                        decimal totalPages     = (decimal)status.Statuses.Sum(s => s.Count);
                        book.Progress = (completedPages / totalPages) * 100;
                    }
                    else
                    {
                        book.Progress = 0.0M;
                    }
                }

                var url = await StoreFile(book.Id, command.Content.FileName, command.Content.Contents, cancellationToken);

                command.Content.FilePath = url;
                command.Content.IsPublic = true;
                var file = await _fileRepository.AddFile(command.Content, cancellationToken);

                await _bookRepository.AddBookContent(book.Id, file.Id, command.Language, command.MimeType, cancellationToken);

                command.Result = await _bookRepository.GetBookContent(book.LibraryId, book.Id, command.Language, command.MimeType, cancellationToken);;
            }

            return(await base.HandleAsync(command, cancellationToken));
        }