Exemplo n.º 1
0
        public static void EnsureSeedData(this ApplicationDbContext context, UserManager <ApplicationUser> userManager)
        {
            //if (!context.Users.Any())
            //{
            var adminUser = new CreateUserViewModel {
                Id = Guid.Parse("1F128859-C245-425F-AA73-904CE4078887"), UserName = "******", Password = "******", ConfirmPassword = "******", FamilyName = "Administrator", FirstName = "Administrator"
            };
            var user = adminUser.CreateUserAsync(userManager).Result;

            //添加 Claims
            if (user != null)
            {
                var adminUserClaimDict = new Dictionary <string, string>();
                adminUserClaimDict.Add("Administrator", "Administrator");
                var adminUserClaim = new Models.ManageUserClaimViewModels.AddUserClaimViewModel
                {
                    Id                   = adminUser.Id,
                    FullName             = adminUser.FirstName + adminUser.FirstName,
                    UserName             = adminUser.UserName,
                    PlanAddUserClaimDict = adminUserClaimDict
                };
                var user2 = adminUserClaim.AddUserClaims(userManager).Result;
            }

            //}
        }
        public async Task <IActionResult> AddUser(CreateUserViewModel createUserViewModel)
        {
            if (ModelState.IsValid)
            {
                var newUserInfo = await createUserViewModel.CreateUserAsync(this._userManager);

                if (newUserInfo != null)
                {
                    //创建未成功,返回创建页面,需重新创建
                    return(RedirectToAction("ListUsers"));
                }
            }
            return(View(createUserViewModel));
        }