Example #1
0
        public async Task Handle(ConfirmUserCommand command)
        {
            UserRegistrationSaga     saga = new UserRegistrationSaga(_commandBus, _passwordHasher);
            UserRegistrationSagaData data = await _sagaRepository.Get <UserRegistrationSagaData>(command.ConfirmationId);

            if (data == null)
            {
                throw new InvalidOperationException();
            }

            await saga.RaiseEvent(data, saga.ConfirmUserCommand, command);

            await _sagaRepository.Save(command.ConfirmationId, data);
        }
        public async Task Handle(RegisterUserCommand command)
        {
            AccountReadModel accountReadModel = await _query.Query <Task <AccountReadModel>, string>(command.LoginName);

            if (accountReadModel != null)
            {
                throw new LoginNameAlreadyUsedException(command.LoginName);
            }

            if (await _sagaRepository.Get <UserRegistrationSagaData>(x => x.LoginName == command.LoginName) != null)
            {
                throw new LoginNameAlreadyUsedException(command.LoginName);
            }

            UserRegistrationSaga     saga = new UserRegistrationSaga(_commandBus, _passwordHasher);
            UserRegistrationSagaData data = new UserRegistrationSagaData {
                Id = command.Id
            };
            await saga.RaiseEvent(data, saga.RegisterUserCommand, command);

            await _sagaRepository.Save(data.Id, data);
        }