Ejemplo n.º 1
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     BusinessModelDBContext db = new BusinessModelDBContext();
 }
Ejemplo n.º 2
0
        protected override void Seed(ApplicationDbContext context)
        {
            BusinessModelDBContext db = new BusinessModelDBContext();
            Random         r          = new Random();
            PasswordHasher hasher     = new PasswordHasher();

            var manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

            // seeding/creating roles
            context.Roles.AddOrUpdate(new IdentityRole {
                Name = "Admin"
            });
            context.Roles.AddOrUpdate(new IdentityRole {
                Name = "Moderator"
            });
            context.Roles.AddOrUpdate(new IdentityRole {
                Name = "Contributor"
            });
            context.Roles.AddOrUpdate(new IdentityRole {
                Name = "Member"
            });
            context.Roles.AddOrUpdate(new IdentityRole {
                Name = "Lecturer"
            });
            context.Roles.AddOrUpdate(new IdentityRole {
                Name = "Student"
            });

            context.Users.AddOrUpdate(new ApplicationUser
            {
                UserName       = "******",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
                FirstName      = "admin",
                SecondName     = "admin",
                PasswordHash   = hasher.HashPassword("admin$1"),
                SecurityStamp  = Guid.NewGuid().ToString()
            });
            ApplicationUser admin = manager.FindByEmail("*****@*****.**");

            if (admin != null)
            {
                manager.AddToRoles(admin.Id, new string[] { "Admin" });
            }

            seedTestUsers(context, manager);
            context.SaveChanges();
            base.Seed(context);
        }