Exemple #1
0
        public void Handle(AdminSyncAllUsersCommand command)
        {
            try
            {
                var repository = this.contextFactory();

                var userList = repository.List(x => x.Active.Equals(true));

                foreach (var user in userList)
                {
                    SyncUserInfoCommand syncPersonInfoCommand = new SyncUserInfoCommand()
                    {
                        UserId = user.UserId
                    };
                    this.bus.Send(syncPersonInfoCommand);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
        public void Handle(SyncUserInfoCommand command)
        {
            try
            {
                var         repository = this.contextFactory();
                Domain.User user       = repository.Get(x => x.UserId == command.UserId);


                var syncInfo = new UserSyncDTO()
                {
                    Active          = user.Active,
                    IntegrationCode = user.IntegrationCode,
                    IsDefaultUser   = user.IsDefaultUser,
                    LanguageId      = user.LanguageId,
                    PersonId        = user.PersonId,
                    Name            = user.Name,
                    SourceId        = command.SourceId,
                    UserId          = user.UserId,
                    UserStatusId    = user.UserStatusId,
                    Email           = user.Email,
                    UserProfileId   = user.UserProfileId
                };


                //Call Notification, create new user
                var _clientNotification = new HttpClient();
                _clientNotification.BaseAddress = new Uri(CustomConfiguration.WebApiNotification);
                HttpResponseMessage responseUser = _clientNotification.PostAsJsonAsync("api/User/AddUser", syncInfo).Result;
                if (!responseUser.IsSuccessStatusCode)
                {
                    LogManager.Error(string.Format("Call WebApiNotification new User Fail User: {0}", syncInfo));
                    throw new HeeelpSyncException();
                }

                //Call Account, create new user
                var _clientAccount = new HttpClient();
                _clientAccount.BaseAddress = new Uri(CustomConfiguration.WebApiAccount);
                HttpResponseMessage responseAccount = _clientAccount.PostAsJsonAsync("api/User/AddUser", syncInfo).Result;
                if (!responseAccount.IsSuccessStatusCode)
                {
                    LogManager.Error(string.Format("Call WebApiAccount new User Fail User: {0}", syncInfo));
                    throw new HeeelpSyncException();
                }

                //Call Contab, create new user
                var _clientContab = new HttpClient();
                _clientContab.BaseAddress = new Uri(CustomConfiguration.WebApiContab);
                HttpResponseMessage responseContab = _clientContab.PostAsJsonAsync("api/User/AddUser", syncInfo).Result;

                if (!responseAccount.IsSuccessStatusCode)
                {
                    LogManager.Error(string.Format("Call WebApiContab new User Fail User: {0}", syncInfo));
                    throw new HeeelpSyncException();
                }

                //Call Promotion, create new user
                var _clientPromotion = new HttpClient();
                _clientPromotion.BaseAddress = new Uri(CustomConfiguration.WebApiPromotion);
                HttpResponseMessage responsePromotion = _clientPromotion.PostAsJsonAsync("api/User/AddUser", syncInfo).Result;
                if (!responseUser.IsSuccessStatusCode)
                {
                    LogManager.Error(string.Format("Call WebApiNotification new User Fail User: {0}", syncInfo));
                    throw new HeeelpSyncException();
                }

                //Call Social, create new user
                var _clientSocial = new HttpClient();
                _clientSocial.BaseAddress = new Uri(CustomConfiguration.WebApiSocial);
                HttpResponseMessage responseSocial = _clientSocial.PostAsJsonAsync("api/Sync/AddUser", syncInfo).Result;
                if (!responseUser.IsSuccessStatusCode)
                {
                    LogManager.Error(string.Format("Call WebApiSocial new User Fail User: {0}", syncInfo));
                    throw new HeeelpSyncException();
                }


                //disparar o evento de sincronizacao concluida com sucesso! O eventHandler posteriormente vai disparar o comando de envio de email de ativacao
                this.AddEvent(new UserSyncedSuccessEvent()
                {
                    SourceId        = Guid.NewGuid(),
                    UserId          = command.UserId,
                    IntegrationCode = command.IntegrationCode,
                    PersonId        = command.PersonId
                });
            }
            catch (Exception ex)
            {
                //disparar o evento de sincronizacao concluida com sucesso! O eventHandler posteriormente vai disparar o comando de envio de email de ativacao
                this.AddEvent(new UserNotSyncedEvent()
                {
                    SourceId        = Guid.NewGuid(),
                    UserId          = command.UserId,
                    IntegrationCode = command.IntegrationCode,
                    PersonId        = command.PersonId
                });

                throw;
            }
        }