Example #1
0
        public async Task ExecuteAsync(ReOrderCustomEntitiesCommand command, IExecutionContext executionContext)
        {
            var definition = _customEntityDefinitionRepository.GetByCode(command.CustomEntityDefinitionCode) as IOrderableCustomEntityDefinition;

            if (definition == null || definition.Ordering == CustomEntityOrdering.None)
            {
                throw new InvalidOperationException("Cannot re-order a custom entity type with a definition that does not implement IOrderableCustomEntityDefinition (" + definition.GetType().Name + ")");
            }

            if (!definition.HasLocale && command.LocaleId.HasValue)
            {
                throw new ValidationException("Cannot order by locale because this custom entity type is not permitted to have a locale (" + definition.GetType().FullName + ")");
            }

            var affectedIds = await _customEntityStoredProcedures.ReOrderAsync(
                command.CustomEntityDefinitionCode,
                command.OrderedCustomEntityIds,
                command.LocaleId
                );

            foreach (var affectedId in affectedIds)
            {
                _customEntityCache.Clear(command.CustomEntityDefinitionCode, affectedId);
            }

            var messages = affectedIds.Select(i => new CustomEntityOrderingUpdatedMessage()
            {
                CustomEntityDefinitionCode = command.CustomEntityDefinitionCode,
                CustomEntityId             = i
            }).ToList();

            await _messageAggregator.PublishBatchAsync(messages);
        }
Example #2
0
        public async Task ExecuteAsync(ReOrderCustomEntitiesCommand command, IExecutionContext executionContext)
        {
            var definition = _customEntityDefinitionRepository.GetByCode(command.CustomEntityDefinitionCode) as IOrderableCustomEntityDefinition;

            if (definition == null || definition.Ordering == CustomEntityOrdering.None)
            {
                throw new InvalidOperationException("Cannot re-order a custom entity type with a definition that does not implement IOrderableCustomEntityDefinition (" + definition.GetType().Name + ")");
            }

            if (!definition.HasLocale && command.LocaleId.HasValue)
            {
                throw new ValidationException("Cannot order by locale because this custom entity type is not permitted to have a locale (" + definition.GetType().FullName + ")");
            }

            var affectedIds = await _customEntityStoredProcedures.ReOrderAsync(
                command.CustomEntityDefinitionCode,
                command.OrderedCustomEntityIds,
                command.LocaleId
                );

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