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
        public Task Handle(SportNameChanged message)
        {
            var updateBuilder = new UpdateDefinitionBuilder <SportDto>();

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

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

            var updateFixtureBuilder = new UpdateDefinitionBuilder <FixtureDto>();
            var updateDefinition     = updateFixtureBuilder.Set(s => s.Sport.Name, message.Name);

            foreach (var fixtureId in fixtureMap.FixtureIds)
            {
                _repository.Update(fixtureId, updateDefinition);
            }

            Console.WriteLine($"Handled sport name changed event {message.AggregateId}:{message.Name}");
            return(Task.CompletedTask);
        }