示例#1
0
        public static void createRolesandUsers()
        {
            OnlineCourseDb context = new OnlineCourseDb();

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

            // In Startup iam creating first Admin Role and creating a default Admin User
            if (!roleManager.RoleExists("SuperAdmin"))
            {
                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "SuperAdmin";
                roleManager.Create(role);

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

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

                string userPWD = "Admin@123456";

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

                //Add default User to Role Admin
                if (chkUser.Succeeded)
                {
                    var resultRole = UserManager.AddToRole(user.Id, "SuperAdmin");
                }
            }

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

            // creating Creating Employee role
            if (!roleManager.RoleExists("Student"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Student";
                roleManager.Create(role);
            }
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            OnlineCourseDb db   = new OnlineCourseDb();
            DataSeeder     seed = new DataSeeder(db);

            GlobalConfiguration.Configuration.Formatters.Add(new
                                                             FormMultipartEncodedMediaTypeFormatter(new MultipartFormatterSettings()));
            seed.SeedDefaultCountry();
            seed.SeedLevels();
            IdentitySeed.createRolesandUsers();
        }
示例#3
0
 public DataSeeder(OnlineCourseDb db)
 {
     Db = db;
 }
 public BaseController()
 {
     Db = new OnlineCourseDb();
 }
        // new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));

        public BaseController(ApplicationUserManager manager, SignInManager <ApplicationUser, string> signInManager)
        {
            UserManager   = manager;
            SignInManager = signInManager;
            Db            = new OnlineCourseDb();
        }