コード例 #1
0
        public async Task Handle(UpdateSpeechCommandMessage command)
        {
            if (command == null)
            {
                throw new ArgumentNullApplicationException(nameof(command));
            }

            var speech = await _eventStoreRepository.GetByIdAsync <Domain.SpeechAggregate.Speech>(command.SpeechId);

            if (speech == null || speech.Id == Guid.Empty)
            {
                throw new NotFoundApplicationException($"speech not found {command.SpeechId}");
            }
            long committedVersion = command.OriginalVersion;

            if (command.Title != null && speech.Title.Value != command.Title)
            {
                speech.ChangeTitle(new Title(command.Title), committedVersion++);
            }
            if (command.Description != null && speech.Description.Value != command.Description)
            {
                speech.ChangeDescription(new Description(command.Description), committedVersion++);
            }
            if (command.Url != null && speech.Url.Value != command.Url)
            {
                speech.ChangeUrl(new UrlValue(command.Url), committedVersion++);
            }

            if (command.Type != null && speech.Type != new SpeechType(command.Type.Value))
            {
                speech.ChangeType(new SpeechType(command.Type.Value), committedVersion);
            }

            await _speechRepository.UpdateAsync(speech);

            await _domainEventSubscriber.Subscribe(speech);
        }
        public async Task Handle(UpdateSpeechCommandMessage command)
        {
            if (command == null)
            {
                throw new ArgumentNullApplicationException(nameof(command));
            }

            var speech = await _eventStoreRepository.GetByIdAsync <Domain.SpeechAggregate.Speech>(command.SpeechId);

            if (speech == null)
            {
                throw new NotFoundApplicationException($"speech not found {command.SpeechId}");
            }

            if (speech.Title.Value != command.Title)
            {
                speech.ChangeTitle(command.Title, command.OriginalVersion);
            }
            await _speechRepository.UpdateAsync(speech);

            await _domainEventSubscriber.Subscribe(speech);

            _unitOfWork.Commit();
        }