public override async Task <IdentityResult> CreateAsync(IdentityUser user)
        {
            /* We want to update a customized user property after a user created.
             * But we lack with this code. I tried many UOW combination without luck.
             * Maybe you can help us.
             * You have to uncomment below codes.. */

            IdentityResult identityResult;

            try
            {
                // Create a user.
                identityResult = await base.CreateAsync(user);

                user.SetProperty("DisplayName", user.UserName);
            }
            // Can not catch any exception like this!
            catch (Exception e)
            {
                Console.WriteLine(e);
                identityResult = IdentityResult.Failed();
            }

            return(identityResult);
        }
        private async Task CreateUserWithExtraProperty()
        {
            //"test" user
            const string userName = "******";
            var          user     = await UserRepository.FindByNormalizedUserNameAsync(LookupNormalizer.NormalizeName(userName));

            if (user != null)
            {
                return;
            }

            user = new Volo.Abp.Identity.IdentityUser(
                GuidGenerator.Create(),
                userName,
                "*****@*****.**"
                )
            {
                Name = userName
            };
            user.SetProperty("WarehouseId", GuidGenerator.Create());
            (await UserManager.CreateAsync(user, "1q2w3E*")).CheckErrors();
        }
Ejemplo n.º 3
0
        public virtual async Task <IdentityUserDto> CreateAsync(IdentityUserCreateDto input)
        {
            try
            {
                await IdentityOptions.SetAsync();
            }
            catch (Exception e)
            {
                throw;
            }

            var user = new IdentityUser(
                GuidGenerator.Create(),
                input.UserName,
                input.Email,
                CurrentTenant.Id
                );

            input.MapExtraPropertiesTo(user);

            // TODO: this is another issue.
            // It throws an error without casting the type int to enum type before saving the user
            var      userType = user.GetProperty <int>("Type");
            UserType type     = (UserType)userType;

            user.SetProperty("Type", type);

            (await UserManager.CreateAsync(user, input.Password)).CheckErrors();
            await UpdateUserByInput(user, input);

            (await UserManager.UpdateAsync(user)).CheckErrors();

            await CurrentUnitOfWork.SaveChangesAsync();

            return(ObjectMapper.Map <IdentityUser, IdentityUserDto>(user));
        }