public override async Task <AddArticleContentRequest> HandleAsync(AddArticleContentRequest command, CancellationToken cancellationToken = new CancellationToken()) { if (string.IsNullOrWhiteSpace(command.Language)) { var library = await _libraryRepository.GetLibraryById(command.LibraryId, cancellationToken); if (library == null) { throw new BadRequestException(); } command.Language = library.Language; } var issue = await _issueRepository.GetIssue(command.LibraryId, command.PeriodicalId, command.VolumeNumber, command.IssueNumber, cancellationToken); if (issue == null) { throw new BadRequestException(); } var article = await _articleRepository.GetArticleById(command.LibraryId, command.PeriodicalId, command.VolumeNumber, command.IssueNumber, command.ArticleId, cancellationToken); if (article != null) { var name = GenerateChapterContentUrl(command.PeriodicalId, command.IssueNumber, command.ArticleId, command.Language, command.MimeType); var actualUrl = await _fileStorage.StoreTextFile(name, command.Contents, cancellationToken); var fileModel = new Models.FileModel { MimeType = command.MimeType, FilePath = actualUrl, IsPublic = issue.IsPublic, FileName = name }; var file = await _fileRepository.AddFile(fileModel, cancellationToken); var issueContent = new ArticleContentModel { PeriodicalId = command.PeriodicalId, IssueId = issue.Id, ArticleId = command.ArticleId, Language = command.Language, MimeType = command.MimeType, FileId = file.Id }; command.Result = await _articleRepository.AddArticleContent(command.LibraryId, issueContent, cancellationToken); if (file.IsPublic) { var url = await ImageHelper.TryConvertToPublicFile(file.Id, _fileRepository, cancellationToken); command.Result.ContentUrl = url; } } return(await base.HandleAsync(command, cancellationToken)); }