Ejemplo n.º 1
0
        protected override void Seed(B1625DbContext context)
        {
            base.Seed(context);

            UserAccountManager accountManager = UserAccountManager.Create(context);
            UserRoleManager    roleManager    = new UserRoleManager(new RoleStore <UserRole>(context));


            roleManager.Create(new UserRole()
            {
                Name = "Administrators"
            });
            roleManager.Create(new UserRole()
            {
                Name = "Moderators"
            });
            roleManager.Create(new UserRole()
            {
                Name = "Users"
            });

            var admin = accountManager.FindByName("admin");

            if (admin == null)
            {
                admin = new UserAccount()
                {
                    UserName = "******", Email = "*****@*****.**"
                };
                var profile = new UserProfile()
                {
                    AccountId        = admin.Id,
                    Gender           = Gender.Male,
                    RegistrationDate = DateTime.Now
                };
                admin.Profile = profile;
                var result = accountManager.Create(admin, "adminadmin");
                if (!result.Succeeded)
                {
                }
                accountManager.AddToRole(admin.Id, "Administrators");
                accountManager.AddToRole(admin.Id, "Users");

                context.SaveChanges();
            }
        }