public async Task Handle(CompetitorNameChanged message)
        {
            var updateBuilder = new UpdateDefinitionBuilder <CompetitorDto>();

            _repository.Update(message.AggregateId, updateBuilder.Set(s => s.Name, message.Name));

            var fixtureMap = _repository.Get <CompetitorToFixtureMapDto>(message.AggregateId);

            var updateFixtureBuilder = new UpdateDefinitionBuilder <FixtureDto>();


            var updateDefinition1 = updateFixtureBuilder.Set(s => s.Competitor1.Name, message.Name);
            var updateDefinition2 = updateFixtureBuilder.Set(s => s.Competitor2.Name, message.Name);

            foreach (var fixtureId in fixtureMap.FixtureIds)
            {
                var fixture = _repository.Get <FixtureDto>(fixtureId);
                if (fixture.Competitor1.Id == message.AggregateId)
                {
                    _repository.Update(fixtureId, updateDefinition1);
                }
                if (fixture.Competitor2.Id == message.AggregateId)
                {
                    _repository.Update(fixtureId, updateDefinition2);
                }
            }

            Console.WriteLine($"Handled competitor name changed event {message.AggregateId}:{message.Name}");
        }
Exemplo n.º 2
0
 protected void Apply(CompetitorNameChanged ev)
 {
     _name = ev.Name;
 }