コード例 #1
0
        private void UserCreatedSucess(Domain.User user, GeneralEnumerators.EnumEmailAcvtiveType messageCodeType)
        {
            //disparar o evento de usuario criado com sucesso para sincronizacao dos dados de usuario nos demais modulos
            user.AddEvent(new UserCreatedSuccessEvent
            {
                //SourceId = user.Id,
                UserId          = user.UserId,
                IntegrationCode = user.IntegrationCode,
                PersonId        = user.PersonId,
                IsDefaultUser   = user.IsDefaultUser,
                UserStatusId    = user.UserStatusId,
                LanguageId      = user.LanguageId,
                Active          = user.Active,
                Email           = user.Email
            });


            var person   = user.Person;
            var employee = _personDao.GetCompany(user.PersonId);

            if (employee.PersonTypeId == (byte)GeneralEnumerators.EnumPersonType.Natural_Person)
            {
                var company = _personDao.GetCompany((int)employee.PersonFatherId);

                //disparar o comando para criacao do email de ativacao
                CreateActivationRequestCommand command = new CreateActivationRequestCommand();
                command.SourceId            = Guid.NewGuid();
                command.PersonToId          = user.PersonId;
                command.MessageCodeType     = messageCodeType;
                command.UserIntegrationCode = user.IntegrationCode;
                this.bus.Send(command);
            }
        }
コード例 #2
0
 public void UserCreatedFailure(Domain.User user)
 {
     //disparar os eventos de tratamento de erro
     user.AddEvent(new UserNotCreatedEvent
     {
         SourceId        = user.Id,
         UserId          = user.UserId,
         IntegrationCode = user.IntegrationCode,
         PersonId        = user.PersonId,
         IsDefaultUser   = user.IsDefaultUser,
         UserStatusId    = user.UserStatusId,
         LanguageId      = user.LanguageId,
         Active          = user.Active
     });
 }
コード例 #3
0
        public void Handle(ActivateUserCommand command)
        {
            var repository = this.contextFactory();

            // a partir da pessoa fisica que recebeu o email de ativacao
            Domain.User userPF = repository.Get(x => x.IntegrationCode == command.IntegrationCode);

            try
            {
                if (userPF.UserStatusId != (byte)GeneralEnumerators.EnumUserStatus.Ativo)
                {
                    //atualiza os dados do usuario vinculado a pessoa fisica
                    userPF.SmartPhoneNumber = command.PhoneNumber;
                    userPF.LoginPassword    = command.Password;
                    userPF.UserStatusId     = (byte)GeneralEnumerators.EnumUserStatus.Ativo;
                    userPF.UserHistory.Add(this.CreateUserHistory(userPF));


                    repository.Update(userPF);
                    userPF.AddEvent(new UserActivatedEvent()
                    {
                        UserPFId = userPF.UserId
                    });

                    repository.AddEventToBus(userPF);
                    //atualiza o Status da Pessoa Fisica
                    this.bus.Send(new UpdatePersonStatusCommand()
                    {
                        PersonId = userPF.PersonId, Status = GeneralEnumerators.EnumPersonStatus.CadastroAprovado
                    });
                    //enviar o email de boas vindas
                    this.bus.Send(new SendWelcomeMessageCommand()
                    {
                        UserIntegrationCode = userPF.IntegrationCode
                    });
                }

                var person = _personDao.GetByPersonId(userPF.PersonId);
                //agora, atualiza tambem os dados do usuario vinculado com a pessoa juridica. Considerar que antes de aceitar um usuario, eh necessario validar se o email ainda nao existe no banco.
                Domain.User userPJ = repository.Get(x => x.PersonId == person.PersonFatherId && x.Email == userPF.Email);
                if (userPJ.UserStatusId != (byte)GeneralEnumerators.EnumUserStatus.Ativo)
                {
                    userPJ.SmartPhoneNumber = command.PhoneNumber;
                    userPJ.LoginPassword    = command.Password;
                    userPJ.UserStatusId     = (byte)GeneralEnumerators.EnumUserStatus.Ativo;
                    userPJ.UserHistory.Add(this.CreateUserHistory(userPJ));
                    repository.Update(userPJ);
                    //atualiza o Status da Pessoa Fisica
                    this.bus.Send(new UpdatePersonStatusCommand()
                    {
                        PersonId = userPJ.PersonId, Status = GeneralEnumerators.EnumPersonStatus.CadastroAprovado
                    });
                }
            }
            catch (Exception ex)
            {
                NotActivatedNewUserEvent passwordNotChangedEvent = new NotActivatedNewUserEvent()
                {
                    IntegrationCode = command.IntegrationCode
                };
                userPF.AddEvent(passwordNotChangedEvent);
                repository.AddEventToBus(userPF);
                throw;
            }
        }