Ejemplo n.º 1
0
        // Command -> Event - how to track this simple use case?
        // Command -> Event -> Event -> Command -> Event ... or this one?

        public async Task HandleAsync(CreateDiscount command, ICorrelationContext context)
        {
            // Customer validation
            var customer = await _customersRepository.GetAsync(command.CustomerId);

            if (customer is null)
            {
                //onError: -> publish CreateDiscountRejected
                throw new MicroSException("customer_not_found",
                                          $"Customer with id: '{command.CustomerId}' was not found.");

                // _logger.LogWarning($"Customer with id: '{command.CustomerId}' was not found.");
                // await _busPublisher.PublishAsync(new CreateDiscountRejected(command.CustomerId,
                //     $"Customer with id: '{command.CustomerId}' was not found.",
                //     "customer_not_found"), context);

                // return;
            }

            // Unique code validation
            var discount = new Discount(command.Id, command.CustomerId,
                                        command.Code, command.Percentage);
            await _discountsRepository.AddAsync(discount);

            await _busPublisher.PublishAsync(new DiscountCreated(command.Id,
                                                                 command.CustomerId, command.Code, command.Percentage), context);

            // Send an email about a new discount to the customer
        }
        public async Task HandleAsync(CreateDiscount command, ICorrelationContext context)
        {
            // Customer Validation
            // Unique code validation

            Discount discount = new Discount(command.Id, command.CustomerId, command.Code, command.Percentage);
            await _discountsRepository.AddAsync(discount);

            // Send an email about a new discount to the customer
        }
Ejemplo n.º 3
0
        public async Task HandleAsync(CreateDiscount command, ICorrelationContext context)
        {
            var customer = await _customersRepository.GetAsync(command.CustomerId);

            if (customer is null)
            {
                throw new VirtualMarketException("customer_not_found",
                                                 $"Customer with id: '{command.CustomerId}' was not found.");
            }

            var discount = new Discount(command.Id, command.CustomerId,
                                        command.Code, command.Percentage);
            await _discountsRepository.AddAsync(discount);

            await _busPublisher.PublishAsync(new DiscountCreated(command.Id,
                                                                 command.CustomerId, command.Code, command.Percentage), context);
        }
Ejemplo n.º 4
0
        // Command -> Event - how to track this simple use case?
        // Command -> Event -> Event -> Command -> Event ... or this one?

        public async Task HandleAsync(CreateDiscount command, ICorrelationContext context)
        {
            //Customer validation
            var customer = await _customersRepository.GetAsync(command.CustomerId);

            if (customer is null)
            {
                _logger.LogWarning($"Customer with id: '{command.CustomerId}' was not found.");
                return;
            }
            // Unique code validation
            var discount = new Discount(command.Id, command.CustomerId,
                                        command.Code, command.Percentage);
            await _discountsRepository.AddAsync(discount);

            await _busPublisher.PublishAsync(new DiscountCreated(command.Id,
                                                                 command.CustomerId, command.Code, command.Percentage), context);

            //publish to bus
            // Send an email about a new discount to the customer
        }
Ejemplo n.º 5
0
        public async Task HandleAsync(CreateDiscount command, ICorrelationContext context)
        {
            var customer = await _customerRepository.GetAsync(command.CustomerId);

            if (customer is null)
            {
                _logger.LogWarning($"Customer with id: '{command.CustomerId}' was not found.");
                await _busPublisher.PublishAsync(new CreateDiscountRejected(command.CustomerId,
                                                                            $"Customer with id: '{command.CustomerId}' was not found",
                                                                            "customer_not_found"), context);

                return;
            }


            var discount = new Discount(command.Id, command.CustomerId,
                                        command.Code, command.Percentage);
            await _discountsRepository.AddAsync(discount);

            await _busPublisher.PublishAsync(new DiscountCreated(command.Id,
                                                                 command.CustomerId, command.Code, command.Percentage), context);
        }