Exemple #1
0
        public async Task ExecuteAsync(AddCustomEntityDraftVersionCommand command, IExecutionContext executionContext)
        {
            var definitionCode = await QueryVersionAndGetDefinitionCode(command).FirstOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(definitionCode, command.CustomEntityId);

            _permissionValidationService.EnforceIsLoggedIn(executionContext.UserContext);
            _permissionValidationService.EnforceCustomEntityPermission <CustomEntityUpdatePermission>(definitionCode, executionContext.UserContext);

            var newVersionId = await _customEntityStoredProcedures.AddDraftAsync(
                command.CustomEntityId,
                command.CopyFromCustomEntityVersionId,
                executionContext.ExecutionDate,
                executionContext.UserContext.UserId.Value);

            command.OutputCustomEntityVersionId = newVersionId;
            _customEntityCache.Clear(definitionCode, command.CustomEntityId);

            await _messageAggregator.PublishAsync(new CustomEntityDraftVersionAddedMessage()
            {
                CustomEntityId             = command.CustomEntityId,
                CustomEntityVersionId      = newVersionId,
                CustomEntityDefinitionCode = definitionCode
            });
        }
Exemple #2
0
        public async Task ExecuteAsync(AddCustomEntityDraftVersionCommand command, IExecutionContext executionContext)
        {
            var definitionCode = await QueryVersionAndGetDefinitionCode(command).FirstOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(definitionCode, command.CustomEntityId);

            _permissionValidationService.EnforceIsLoggedIn(executionContext.UserContext);
            _permissionValidationService.EnforceCustomEntityPermission <CustomEntityUpdatePermission>(definitionCode, executionContext.UserContext);

            var newVersionId = await _customEntityStoredProcedures.AddDraftAsync(
                command.CustomEntityId,
                command.CopyFromCustomEntityVersionId,
                executionContext.ExecutionDate,
                executionContext.UserContext.UserId.Value);

            command.OutputCustomEntityVersionId = newVersionId;

            await _transactionScopeFactory.QueueCompletionTaskAsync(_dbContext, () => OnTransactionComplete(
                                                                        command,
                                                                        definitionCode,
                                                                        newVersionId)
                                                                    );
        }