public async Task ExecuteAsync(UpdateImageAssetCommand command, IExecutionContext executionContext) { bool hasNewFile = command.File != null; var imageAsset = await _dbContext .ImageAssets .Include(a => a.ImageAssetTags) .ThenInclude(a => a.Tag) .FilterById(command.ImageAssetId) .SingleOrDefaultAsync(); imageAsset.FileDescription = command.Title; imageAsset.FileName = SlugFormatter.ToSlug(command.Title); imageAsset.DefaultAnchorLocation = command.DefaultAnchorLocation; _entityTagHelper.UpdateTags(imageAsset.ImageAssetTags, command.Tags, executionContext); _entityAuditHelper.SetUpdated(imageAsset, executionContext); using (var scope = _transactionScopeFactory.Create(_dbContext)) { if (hasNewFile) { await _imageAssetFileService.SaveAsync(command.File, imageAsset, nameof(command.File)); } await _dbContext.SaveChangesAsync(); scope.Complete(); } if (hasNewFile) { await _imageAssetFileCache.ClearAsync(imageAsset.ImageAssetId); } _imageAssetCache.Clear(imageAsset.ImageAssetId); }
public async Task ExecuteAsync(DeleteImageAssetCommand command, IExecutionContext executionContext) { var imageAsset = await _dbContext .ImageAssets .FilterById(command.ImageAssetId) .SingleOrDefaultAsync(); if (imageAsset != null) { imageAsset.IsDeleted = true; using (var scope = _transactionScopeFactory.Create(_dbContext)) { await _commandExecutor.ExecuteAsync(new DeleteUnstructuredDataDependenciesCommand(ImageAssetEntityDefinition.DefinitionCode, imageAsset.ImageAssetId)); await _dbContext.SaveChangesAsync(); scope.Complete(); } _imageAssetCache.Clear(command.ImageAssetId); await _messageAggregator.PublishAsync(new ImageAssetDeletedMessage() { ImageAssetId = command.ImageAssetId }); } }
private Task OnTransactionComplete(DeleteImageAssetCommand command) { _imageAssetCache.Clear(command.ImageAssetId); return(_messageAggregator.PublishAsync(new ImageAssetDeletedMessage() { ImageAssetId = command.ImageAssetId })); }
private async Task OnTransactionComplete(bool hasNewFile, ImageAsset imageAsset) { if (hasNewFile) { await _imageAssetFileCache.ClearAsync(imageAsset.ImageAssetId); } _imageAssetCache.Clear(imageAsset.ImageAssetId); await _messageAggregator.PublishAsync(new ImageAssetUpdatedMessage() { ImageAssetId = imageAsset.ImageAssetId, HasFileChanged = hasNewFile }); }