예제 #1
0
        private User ArrangeUsersDbSetWithOneDataConsumer()
        {
            var dataConsumer = new DataConsumerUser
            {
                Id                    = 123,
                Role                  = Role.DataConsumer,
                EmailAddress          = "*****@*****.**",
                Name                  = "*****@*****.**",
                Organization          = "org org",
                PhoneNumber           = "123",
                AdditionalPhoneNumber = "321"
            };

            ArrangeUsersFrom(new List <User> {
                dataConsumer
            });
            return(dataConsumer);
        }
예제 #2
0
        private async Task <DataConsumerUser> CreateDataConsumerUser(IdentityUser identityUser, int nationalSocietyId, CreateDataConsumerRequestDto createDataConsumerRequestDto)
        {
            var nationalSociety = await _dataContext.NationalSocieties.Include(ns => ns.ContentLanguage)
                                  .SingleOrDefaultAsync(ns => ns.Id == nationalSocietyId);

            if (nationalSociety == null)
            {
                throw new ResultException(ResultKey.User.Registration.NationalSocietyDoesNotExist);
            }

            if (nationalSociety.IsArchived)
            {
                throw new ResultException(ResultKey.User.Registration.CannotCreateUsersInArchivedNationalSociety);
            }

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

            var user = new DataConsumerUser
            {
                IdentityUserId        = identityUser.Id,
                EmailAddress          = identityUser.Email,
                Name                  = createDataConsumerRequestDto.Name,
                PhoneNumber           = createDataConsumerRequestDto.PhoneNumber,
                AdditionalPhoneNumber = createDataConsumerRequestDto.AdditionalPhoneNumber,
                Organization          = createDataConsumerRequestDto.Organization,
                ApplicationLanguage   = defaultUserApplicationLanguage
            };

            var userNationalSociety = CreateUserNationalSocietyReference(nationalSociety, user);

            await _dataContext.AddAsync(userNationalSociety);

            await _dataContext.SaveChangesAsync();

            return(user);
        }