Beispiel #1
0
        public async Task HandleAsync(UpdateEntryOrder message, IRequestInfo requestInfo)
        {
            var entries = await _repository.GetEntriesAsync(message.BusinessId);

            var specifications = entries.OrderBy(s => s.Order).ToList();

            var updating = specifications.FirstOrDefault(d => d.Id == message.EntryId);

            if (updating is null)
            {
                _logger.LogWarning($"No entry found with ID: {message.EntryId}");
                _publisher.PublishEvent(new EntryOrderUpdateRejected(Codes.InvalidId, $"Entry with the id {message.EntryId} could not be found."), requestInfo);
                return;
            }

            var replacing = specifications.FirstOrDefault(s => s.Order == message.Order);
            int oldOrder  = updating.Order;

            _specificationAggregate.UpdateOrder(updating, message.Order);
            _specificationAggregate.UpdateOrder(replacing, oldOrder);

            await _repository.UpdateAsync(updating);

            await _repository.UpdateAsync(replacing);

            _publisher.PublishEvent(new EntryOrderUpdated(), requestInfo);
        }
Beispiel #2
0
        public async Task HandleAsync(DeprecateDataEntry message, IRequestInfo requestInfo)
        {
            var entries = await _repository.GetEntriesAsync(message.BusinessId);

            var dataSpecifications = entries.ToList();

            if (!dataSpecifications.Any())
            {
                _logger.LogWarning($"No entries found with business ID: {message.BusinessId}");
                _publisher.PublishEvent(new DataEntryDeprecationRejected(Codes.InvalidBusinessId, $"Entries with the id {message.BusinessId} could not be found."), requestInfo);
                return;
            }

            var spec = dataSpecifications.FirstOrDefault(d => d.Id == message.Id);

            if (spec is null)
            {
                _logger.LogWarning($"No entry found with ID: {message.Id}");
                _publisher.PublishEvent(new DataEntryDeprecationRejected(Codes.InvalidId, $"Entry with the id {message.Id} could not be found."), requestInfo);
                return;
            }

            if (spec.IsMandatory)
            {
                _logger.LogInformation($"{spec.Label} is  set as mandatory and cannot be deprecated.");
                _publisher.PublishEvent(new DataEntryDeprecationRejected(Codes.InvalidId, $"{spec.Label} is  set as mandatory and cannot be deprecated."), requestInfo);
                return;
            }

            _specificationAggregate.Deprecate(spec);
            await _repository.UpdateAsync(spec);

            dataSpecifications.Remove(spec);
            dataSpecifications = dataSpecifications.Where(s => s.IsMandatory == false).ToList();

            var ordered = dataSpecifications.OrderBy(d => d.Order).ToList();

            for (int i = 0; i < ordered.Count; i++)
            {
                _specificationAggregate.UpdateOrder(ordered[i], i + 1);
                await _repository.UpdateAsync(ordered[i]);
            }

            _publisher.PublishEvent(new DataEntryDeprecated(), requestInfo);
            _logger.LogInformation($"Entry deprecated with id: {message.Id} and other entries re-ordered.");
        }