Example #1
0
        public async Task <Result> Create(int nationalSocietyId, CreateSupervisorRequestDto createSupervisorRequestDto)
        {
            try
            {
                string         securityStamp;
                SupervisorUser user;
                using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    var identityUser = await _identityUserRegistrationService.CreateIdentityUser(createSupervisorRequestDto.Email, Role.Supervisor);

                    securityStamp = await _identityUserRegistrationService.GenerateEmailVerification(identityUser.Email);

                    user = await CreateSupervisorUser(identityUser, nationalSocietyId, createSupervisorRequestDto);

                    transactionScope.Complete();
                }

                await _verificationEmailService.SendVerificationEmail(user, securityStamp);

                return(Success(ResultKey.User.Registration.Success));
            }
            catch (ResultException e)
            {
                _loggerAdapter.Debug(e);
                return(e.Result);
            }
        }
        public async Task <Result> Create(CreateGlobalCoordinatorRequestDto dto)
        {
            try
            {
                string securityStamp;
                GlobalCoordinatorUser user;
                using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    var identityUser = await _identityUserRegistrationService.CreateIdentityUser(dto.Email, Role.GlobalCoordinator);

                    securityStamp = await _identityUserRegistrationService.GenerateEmailVerification(identityUser.Email);

                    var defaultUserApplicationLanguage = await _dataContext.ApplicationLanguages
                                                         .SingleOrDefaultAsync(al => al.LanguageCode == EnglishLanguageCode);

                    user = new GlobalCoordinatorUser
                    {
                        IdentityUserId        = identityUser.Id,
                        EmailAddress          = identityUser.Email,
                        Name                  = dto.Name,
                        PhoneNumber           = dto.PhoneNumber,
                        AdditionalPhoneNumber = dto.AdditionalPhoneNumber,
                        Organization          = dto.Organization,
                        Role                  = Role.GlobalCoordinator,
                        ApplicationLanguage   = defaultUserApplicationLanguage
                    };
                    await _dataContext.AddAsync(user);

                    await _dataContext.SaveChangesAsync();

                    transactionScope.Complete();
                }

                await _verificationEmailService.SendVerificationEmail(user, securityStamp);

                return(Success(ResultKey.User.Registration.Success));
            }
            catch (ResultException e)
            {
                _loggerAdapter.Debug(e);
                return(e.Result);
            }
        }