Example #1
0
        private void CreateRolesAndUsers()
        {
            var tournamentDbContext = TournamentSystemDbContext.Create();
            var roleManager         = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(tournamentDbContext));
            var userManager         = new UserManager <User>(new UserStore <User>(tournamentDbContext));

            if (!roleManager.RoleExists(RoleNames.Admin))
            {
                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = RoleNames.Admin;
                roleManager.Create(role);

                //Here we create a Admin super user who will maintain the website

                var user = new User();
                user.UserName = "******";
                user.Email    = "*****@*****.**";

                string userPWD = "A@Z200711";

                var chkUser = userManager.Create(user, userPWD);

                //Add default User to Role Admin
                if (chkUser.Succeeded)
                {
                    var result1 = userManager.AddToRole(user.Id, role.Name);
                }
                //tournamentDbContext.SaveChanges();
            }

            // creating Creating Coach role
            if (!roleManager.RoleExists(RoleNames.Coach))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = RoleNames.Coach;
                roleManager.Create(role);
            }

            // creating Creating Player role
            if (!roleManager.RoleExists(RoleNames.Player))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = RoleNames.Player;
                roleManager.Create(role);
            }

            // creating Creating Sponsor role
            if (!roleManager.RoleExists(RoleNames.Sponsor))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = RoleNames.Sponsor;
                roleManager.Create(role);
            }
        }
Example #2
0
 public static void Intitalize()
 {
     Database.SetInitializer(new MigrateDatabaseToLatestVersion <TournamentSystemDbContext, TournamentsMVC.Data.Migrations.Configuration>());
     TournamentSystemDbContext.Create().Database.Initialize(true);
 }