コード例 #1
0
        public async static Task RegisterAdmin()
        {
            using (var users = new UserRepository())
            {
                var user = users.GetUserByName("admin");

                if (user == null)
                {
                    var adminUser = new CmsUser
                    {
                        UserName = "******",
                        Email = "*****@*****.**",
                        DisplayName = "Administrator"
                    };

                    await users.CreateAsync(adminUser, "Passw0rd1234");
                }
            }

            using (var roles = new RoleRepository())
            {
                if (roles.GetRoleByName("admin") == null)
                {
                    roles.Create(new IdentityRole("admin"));
                }

                if (roles.GetRoleByName("editor") == null)
                {
                    roles.Create(new IdentityRole("editor"));
                }

                if (roles.GetRoleByName("author") == null)
                {
                    roles.Create(new IdentityRole("author"));
                }
            }
        }