Exemplo n.º 1
0
        public B1625DbRepository(string connectionString)
        {
            Database.SetInitializer(new BasicContentInitializer());
            _dbContext = new B1625DbContext(connectionString);

            _accountManager = UserAccountManager.Create(_dbContext);
            _roleManager    = new UserRoleManager(new RoleStore <UserRole>(_dbContext));

            _profilesRepo     = new ProfileRepository(_dbContext);
            _publicationsRepo = new PublicationsRepository(_dbContext);
            _commentsRepo     = new CommentsRepository(_dbContext);
        }
Exemplo n.º 2
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();
            }
        }