Ejemplo n.º 1
0
        private async Task <ResponseMessage> RegisterClient(UserRegisteredIntegrationEvent message)
        {
            var clientCommand = new RegisterClientCommand(message.Id, message.Name, message.Email, message.CPF);
            ValidationResult success;

            using (var scope = _provider.CreateScope())
            {
                var mediator = scope.ServiceProvider.GetRequiredService <IMediatorHandler>();
                success = await mediator.SendCommand(clientCommand);
            }
            return(new ResponseMessage(success));
        }
Ejemplo n.º 2
0
        private async Task <ResponseMessage> RegisterCustomer(UserRegisteredIntegrationEvent userEvent)
        {
            var command = new RegisterCustomerCommand(userEvent.Id, userEvent.Name, userEvent.Email);
            ValidationResult response;

            using (var scope = _serviceProvider.CreateScope())
            {
                var mediator = scope.ServiceProvider.GetRequiredService <IMediatorHandler>();
                response = await mediator.SendCommand(command);
            }

            return(new ResponseMessage(response));
        }
Ejemplo n.º 3
0
        private async Task <ResponseMessage> RegisterCustomerBus(UserRegisterViewModel userRegisterViewModel)
        {
            var user = await _userManager.FindByEmailAsync(userRegisterViewModel.Email);

            var integrationEvent = new UserRegisteredIntegrationEvent(Guid.Parse(user.Id), userRegisterViewModel.Name, userRegisterViewModel.Email);

            try
            {
                return(await _bus.RequestAsync <UserRegisteredIntegrationEvent, ResponseMessage>(integrationEvent));
            }
            catch
            {
                await _userManager.DeleteAsync(user);

                throw;
            }
        }
Ejemplo n.º 4
0
        private async Task <ResponseMessage> ClientRegister(SignUpUserViewModel signUpUserViewModel)
        {
            var user = await _userManager.FindByEmailAsync(signUpUserViewModel.Email);

            var registeredUser = new UserRegisteredIntegrationEvent(
                Guid.Parse(user.Id), signUpUserViewModel.Name, signUpUserViewModel.Email, signUpUserViewModel.CPF);

            try
            {
                return(await _bus.RequestAsync <UserRegisteredIntegrationEvent, ResponseMessage>(registeredUser));
            }
            catch (Exception)
            {
                await _userManager.DeleteAsync(user);

                throw;
            }
        }
Ejemplo n.º 5
0
        private async Task <ResponseMessage> RegisterCustomer(RegisterUser registerUser)
        {
            var user = await _authenticationService._userManager.FindByEmailAsync(registerUser.Email);

            var userRegistered = new UserRegisteredIntegrationEvent(
                Guid.Parse(user.Id), registerUser.Name, registerUser.Email, registerUser.Cpf);

            try
            {
                return(await _bus.RequestAsync <UserRegisteredIntegrationEvent, ResponseMessage>(userRegistered));
            }
            catch
            {
                await _authenticationService._userManager.DeleteAsync(user);

                throw;
            }
        }
Ejemplo n.º 6
0
        private async Task <ResponseMessage> ClientRegister(UserRegister userRegister)
        {
            var user = await _userManager.FindByEmailAsync(userRegister.Email);

            var userRegistered = new UserRegisteredIntegrationEvent(
                Guid.Parse(user.Id), userRegister.Name, userRegister.Email, userRegister.Cpf);

            try
            {
                return(await _bus.RequestAsync <UserRegisteredIntegrationEvent, ResponseMessage>(userRegistered));
            }
            catch
            {
                await _userManager.DeleteAsync(user);

                throw;
            }
        }
Ejemplo n.º 7
0
        public void Listen()
        {
            DomainEventPublisher.Instance.Subscribe(domainEvent =>
            {
                // to do: publish integration events

                if (domainEvent is TenantProvisioned)
                {
                    Console.WriteLine("To Do: TenantProvisionedEvent.");
                    TenantProvisioned evt = domainEvent as TenantProvisioned;
                    //var tenant = tenantRepository.Get(new TenantId(evt.TenantId));

                    TenantProvisionedIntegrationEvent tenantProvisionedEvent = new TenantProvisionedIntegrationEvent(
                        new TenantId(evt.TenantId),
                        evt.Name,
                        evt.Description,
                        evt.Active
                        );
                    tenantProvisionedEvent.TimeStamp = evt.TimeStamp;
                    tenantProvisionedEvent.Version   = evt.Version;

                    //eventStore.Save(new List<IEvent> { tenantProvisionedEvent });
                    _identityAccessIntegrationEventService.PublishThroughEventBusAsync(tenantProvisionedEvent);
                    //return;
                }

                else if (domainEvent is TenantAdministratorRegistered)
                {
                    Console.WriteLine("To Do: TenantAdministratorRegistered.");

                    TenantAdministratorRegistered evt = domainEvent as TenantAdministratorRegistered;
                    TenantId tenantId = new TenantId(evt.TenantId);
                    //var user = userRepository.UserWithUsername(tenantId, evt.Name);

                    UserRegisteredIntegrationEvent userRegisteredIntegrationEvent = new UserRegisteredIntegrationEvent(
                        new TenantId(evt.TenantId),
                        evt.UserId,
                        evt.Name,
                        evt.AdministorName,
                        evt.EmailAddress
                        );
                    userRegisteredIntegrationEvent.TimeStamp = evt.TimeStamp;
                    userRegisteredIntegrationEvent.Version   = evt.Version;

                    //eventStore.Save(new List<IEvent> { userRegisteredIntegrationEvent });
                    _identityAccessIntegrationEventService.PublishThroughEventBusAsync(userRegisteredIntegrationEvent);
                    //return;
                }

                else if (domainEvent is TenantActivated)
                {
                    Console.WriteLine("To Do: TenantActivated.");
                    //return;
                }

                else if (domainEvent is TenantDeactivated)
                {
                    Console.WriteLine("To Do: TenantDeactivated.");
                    //return;
                }


                else if (domainEvent is UserRegistered)
                {
                    Console.WriteLine("To Do: UserRegistered.");

                    UserRegistered evt = domainEvent as UserRegistered;
                    TenantId tenantId  = new TenantId(evt.TenantId);

                    UserRegisteredIntegrationEvent userRegisteredIntegrationEvent = new UserRegisteredIntegrationEvent(
                        new TenantId(evt.TenantId),
                        evt.UserId,
                        evt.Username,
                        evt.Name,
                        evt.EmailAddress
                        );
                    userRegisteredIntegrationEvent.TimeStamp = evt.TimeStamp;
                    userRegisteredIntegrationEvent.Version   = evt.Version;

                    //eventStore.Save(new List<IEvent> { userRegisteredIntegrationEvent });
                    _identityAccessIntegrationEventService.PublishThroughEventBusAsync(userRegisteredIntegrationEvent);
                    //return;
                }

                else if (domainEvent is UserEnablementChanged)
                {
                    Console.WriteLine("To Do: UserEnablementChanged.");
                    //return;
                }

                else if (domainEvent is PersonNameChanged)
                {
                    Console.WriteLine("To Do: PersonNameChanged.");
                    //return;
                }

                else if (domainEvent is PersonContactInformationChanged)
                {
                    Console.WriteLine("To Do: PersonContactInformationChanged.");
                    //return;
                }


                //this.eventStore.Append(domainEvent);
            });
        }