public override async Task <UpdateIssueContentRequest> HandleAsync(UpdateIssueContentRequest command, CancellationToken cancellationToken = new CancellationToken()) { var issue = await _issueRepository.GetIssue(command.LibraryId, command.PeriodicalId, command.VolumeNumber, command.IssueNumber, cancellationToken); if (issue != null) { var issueContent = await _issueRepository.GetIssueContent(command.LibraryId, command.PeriodicalId, command.VolumeNumber, command.IssueNumber, command.Language, command.MimeType, cancellationToken); if (issueContent != null) { if (!string.IsNullOrWhiteSpace(issueContent.ContentUrl)) { await _fileStorage.TryDeleteFile(issueContent.ContentUrl, cancellationToken); } var url = await StoreFile(command.PeriodicalId, command.IssueNumber, command.Content.FileName, command.Content.Contents, cancellationToken); issueContent.ContentUrl = url; await _issueRepository.UpdateIssueContentUrl(command.LibraryId, command.PeriodicalId, command.VolumeNumber, command.IssueNumber, command.Language, command.MimeType, url, cancellationToken); command.Result.Content = issueContent; } else { var url = await StoreFile(command.PeriodicalId, command.IssueNumber, command.Content.FileName, command.Content.Contents, cancellationToken); command.Content.FilePath = url; command.Content.IsPublic = issue.IsPublic; var file = await _fileRepository.AddFile(command.Content, cancellationToken); await _issueRepository.AddIssueContent(command.LibraryId, command.PeriodicalId, command.VolumeNumber, command.IssueNumber, file.Id, command.Language, command.MimeType, cancellationToken); command.Result.HasAddedNew = true; command.Result.Content = await _issueRepository.GetIssueContent(command.LibraryId, command.PeriodicalId, command.VolumeNumber, command.IssueNumber, command.Language, command.MimeType, cancellationToken);; } } return(await base.HandleAsync(command, cancellationToken)); }
public override async Task <AddIssueContentRequest> HandleAsync(AddIssueContentRequest command, CancellationToken cancellationToken = new CancellationToken()) { var issue = await _issueRepository.GetIssue(command.LibraryId, command.PeriodicalId, command.VolumeNumber, command.IssueNumber, cancellationToken); if (issue != null) { var url = await StoreFile(issue.PeriodicalId, issue.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 _issueRepository.AddIssueContent(command.LibraryId, issue.PeriodicalId, issue.VolumeNumber, issue.IssueNumber, file.Id, command.Language, command.MimeType, cancellationToken); command.Result = await _issueRepository.GetIssueContent(command.LibraryId, issue.PeriodicalId, issue.VolumeNumber, issue.IssueNumber, command.Language, command.MimeType, cancellationToken); } return(await base.HandleAsync(command, cancellationToken)); }