Esempio n. 1
0
        public async Task Handle(NewProductFetchedIntegrationEvent @event)
        {
            var productId = await _productRepository.GetIdByExternalTupleAsync(
                @event.ExternalSourceName,
                @event.Id);

            if (productId is null)
            {
                var command = new CreateProductCommand(@event.Name,
                                                       @event.BarCode,
                                                       @event.Price,
                                                       @event.Description,
                                                       new DimensionsDto
                {
                    Length = @event.Length,
                    Width  = @event.Width,
                    Height = @event.Height,
                    Weight = @event.Weight
                },
                                                       new ExternalCreation
                {
                    DuplicationValidated = true,
                    SourceName           = @event.ExternalSourceName,
                    SourceId             = @event.Id
                });
                command.SetAsQueueable();
                _commands.Add(command);
            }
            else
            {
                var command = new UpdateProductCommand(
                    productId.Value,
                    @event.Name,
                    @event.Price,
                    @event.Description,
                    new DimensionsDto
                {
                    Length = @event.Length,
                    Width  = @event.Width,
                    Height = @event.Height,
                    Weight = @event.Weight
                }
                    );
                command.SetAsQueueable();
                _commands.Add(command);
            }
        }