Beispiel #1
0
        private async Task CreateUserWithRole(string name, string email, string password, RoleEnum role,
                                              UserManager <ApplicationUser> userManager)
        {
            var user = new ApplicationUser()
            {
                UserName           = name,
                NormalizedUserName = name.ToUpper(),
                Email           = email,
                NormalizedEmail = email.ToUpper(),
                CreateDate      = DateTime.Now,
                EmailConfirmed  = true,
            };

            var result = await userManager.CreateAsync(user, password);

            if (result.Succeeded)
            {
                await userManager.AddToRoleAsync(user, role.GetEnumDescription());
            }
        }