public async Task HandleAsync(OrderCompleted @event)
        {
            var customer = await _customerRepository.GetAsync(@event.CustomerId);

            if (customer is null)
            {
                throw new CustomerNotFoundException(@event.CustomerId);
            }

            customer.AddCompletedOrder(@event.OrderId);
            _vipPolicy.ApplyVipStatusIfEligible(customer);
            await _customerRepository.UpdateAsync(customer);
        }
Пример #2
0
        public async Task HandleAsync(OrderCompleted @event)
        {
            var customer = await _customerRepository.GetAsync(@event.CustomerId);

            if (customer is null)
            {
                throw new CustomerNotFoundException(@event.CustomerId);
            }

            var isVip = customer.IsVip;

            customer.AddCompletedOrder(@event.OrderId);
            _vipPolicy.ApplyVipStatusIfEligible(customer);
            var vipApplied = !isVip && customer.IsVip;
            await _customerRepository.UpdateAsync(customer);

            var events = _eventMapper.MapAll(customer.Events);
            await _messageBroker.PublishAsync(events.ToArray());
        }