Exemplo n.º 1
0
        // In this method we will create default User roles and Admin user for login
        private void createRolesandUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

            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("Admin"))
            {

                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

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

                var user = new ApplicationUser();
                user.Email = "Gaving30gmail.com";

                string userPWD = "testPassword1.";

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

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

                }
            }
        }
Exemplo n.º 2
0
 public static void CreateRole(string roleName)
 {
     var roleManager = new RoleManager<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
     if (!roleManager.RoleExists(roleName))
     {
         var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
         role.Name = roleName;
         roleManager.Create(role);
     }
 }
        // In this method we will create default User roles and Admin user for login
        private void createRolesandUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

            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("Admin"))
            {

                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

                //Creacion del superadmin

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

                string userPWD = "123456";

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

                //Rol por defecto que es Admin
                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Admin");

                }
            }

            // Creacion de nuevos roles
            if (!roleManager.RoleExists("Cliente"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Cliente";
                roleManager.Create(role);

            }
        }
Exemplo n.º 4
0
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);

            var roleManager = new RoleManager<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));

            if (!roleManager.RoleExists("manager"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "manager";
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("agent"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "agent";
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("doctor"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "doctor";
                roleManager.Create(role);
            }

            using (var rm = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext())))
            using (var um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
            {
                var user = um.FindByEmail("*****@*****.**");
                um.AddToRole(user.Id, "agent");

                user = um.FindByEmail("*****@*****.**");
                um.AddToRole(user.Id, "manager");

                user = um.FindByEmail("*****@*****.**");
                um.AddToRole(user.Id, "doctor");
            }
        }
Exemplo n.º 5
0
        public void createRolesAndUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

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


            if (!roleManager.RoleExists("Customer"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Customer";
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("Employee"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Employee";
                roleManager.Create(role);
            }
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "id,Name")] RoleViewModels roleViewModels)
        {
            if (ModelState.IsValid)
            {
                var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));
                if (roleManager.RoleExists(roleViewModels.Name) == false)
                {
                    var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                    role.Name = roleViewModels.Name;
                    roleManager.Create(role);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(roleViewModels.Name, "Role exists.");
                    return(View(roleViewModels));
                }
            }

            return(View(roleViewModels));
        }
Exemplo n.º 7
0
        private void CreateRoles()
        {
            ApplicationDbContext context = new ApplicationDbContext();

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


            if (!roleManager.RoleExists("Admin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

                var user = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**"
                };
                var result = UserManager.Create(user, "qwerty!12345");

                if (result.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Admin");
                }
            }

            if (!roleManager.RoleExists("Contributor"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Contributor";
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("Visitor"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Visitor";
                roleManager.Create(role);
            }
        }
Exemplo n.º 8
0
        private void CreateRoles()
        {
            ApplicationDbContext context = new ApplicationDbContext();
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));


            //create Admin Role
            if (!roleManager.RoleExists("Admin"))
            {
                // first we create Admin role
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);
            }
            // creating Basic role
            if (!roleManager.RoleExists("Basic"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Basic";
                roleManager.Create(role);
            }
        }
Exemplo n.º 9
0
        private void CreateRolesAndUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

            if (!roleManager.RoleExists("Admin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

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

                string userPass = "******";

                var chkUser = UserManager.Create(user, userPass);
                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Admin");
                }
            }

            if (!roleManager.RoleExists("Customer"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Customer";
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("Musician"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Employee";
                roleManager.Create(role);
            }
        }
Exemplo n.º 10
0
        private void CreateRolesandUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

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

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

            if (!roleManager.RoleExists("Vendor"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole {
                    Name = "Vendor"
                };
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("Assistant"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole {
                    Name = "Assisntant"
                };
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("Client"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole {
                    Name = "Client"
                };
                roleManager.Create(role);
            }
        }
Exemplo n.º 11
0
        private void CreateRolesAndUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

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

            if (!roleManager.RoleExists("Admin"))
            {
                var role = new IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

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

                var checkUser = userManager.Create(user, password);
                if (checkUser.Succeeded)
                {
                    userManager.AddToRole(user.Id, "Admin");
                }
            }

            if (!roleManager.RoleExists("PlusMember"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "PlusMember";
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("Member"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Member";
                roleManager.Create(role);
            }
        }
Exemplo n.º 12
0
        public void utworzRoleIUzytkownikow()
        {
            ApplicationDbContext kontekst = new ApplicationDbContext();
            var menedzerRol          = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(kontekst));
            var menedzerUzytkownikow = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(kontekst));

            if (!menedzerRol.RoleExists("Administrator"))
            {
                var rola = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                rola.Name = "Administrator";
                menedzerRol.Create(rola);

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

                string haslo = "zaq1@WSX";

                var sprUzytkownika = menedzerUzytkownikow.Create(uzytkownik, haslo);
                if (sprUzytkownika.Succeeded)
                {
                    var wynik = menedzerUzytkownikow.AddToRole(uzytkownik.Id, "Administrator");
                }
            }

            if (!menedzerRol.RoleExists("PracownikKlubu"))
            {
                var rola = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                rola.Name = "PracownikKlubu";
                menedzerRol.Create(rola);
            }

            if (!menedzerRol.RoleExists("Trener"))
            {
                var rola = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                rola.Name = "Trener";
                menedzerRol.Create(rola);
            }
        }
Exemplo n.º 13
0
        // This method will create a default User roles and Admin user for login
        public void CreateUserAndRoles()
        {
            ApplicationDbContext context = new ApplicationDbContext();

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

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

                //Create default user superAdmin who maintain the website
                var user = new ApplicationUser();
                user.UserName = "******";
                user.Email    = "*****@*****.**";

                string userPWD = "DefaultAdmin@123";

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

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

            // creating Creating Manager role
            if (!roleManager.RoleExists("Agents"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Agents";
                roleManager.Create(role);
            }
        }
Exemplo n.º 14
0
        // En este método se crearán los Roles predeterminados y el usuario
        // que actuará como Administrador predeterminado
        private void crearRolesyUsuariosPredeterminados()
        {
            ApplicationDbContext context = new ApplicationDbContext();
            var roleManager =
                new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var userManager =
                new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

            // Se crea el rol de Administrador y el usuario Administrador predeterminado
            if (!roleManager.RoleExists("Administrador"))
            {
                // Si no existe, se crea el rol de Administrador
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();


                role.Name = "Administrador";
                roleManager.Create(role);
                // Se crea el Administrador predeterminado que mantendrá el sitio web.
                // Se recomienda cambiar la contraseña al entrar por primera vez
                // en la aplicación Web
                var user = new ApplicationUser();
                user.UserName = "******";
                user.Email    = "*****@*****.**";
                string userPWD = "admin123";
                var    chkUser = userManager.Create(user, userPWD);
                // Agregar el administrador predeterminado al rol de Administrador
                if (chkUser.Succeeded)
                {
                    var result1 = userManager.AddToRole(user.Id, "Administrador");
                }
            }
            // Si no exsiste, se crea el rol Usuario
            if (!roleManager.RoleExists("Usuario"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Usuario";
                roleManager.Create(role);
            }
        }
Exemplo n.º 15
0
        public ActionResult CreateRole(CreateRoleVM vm)
        {
            if (ModelState.IsValid)
            {
                db = new ApplicationDbContext();
                var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db));
                if (!roleManager.RoleExists(vm.Roles))
                {
                    var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                    role.Name = vm.Roles;
                    roleManager.Create(role);
                    return(Json(new { success = true }));
                }
                else
                {
                    ModelState.AddModelError("Role Already exist", "Role Already exist");
                    return(PartialView("_RoleCreate", vm));
                }
            }

            return(PartialView("_RoleCreate", vm));
        }
Exemplo n.º 16
0
        private void createRoles()
        {
            ApplicationDbContext context = new ApplicationDbContext();
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

            if (!roleManager.RoleExists("Admin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

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

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

                if (chkUser.Succeeded)
                {
                    var result1 = userManager.AddToRole(user.Id, "Admin");
                }
            }

            if (!roleManager.RoleExists("Employee"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Employee";
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("Customer"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Customer";
                roleManager.Create(role);
            }
        }
Exemplo n.º 17
0
        //In this method we will create default user roles and admin user for login
        private void CreateRolesAndUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

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

            //creating customer role
            if (!RoleManager.RoleExists("Customer"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Customer";
                RoleManager.Create(role);
            }

            //creating employee role
            if (!RoleManager.RoleExists("Employee"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Employee";
                RoleManager.Create(role);
            }
        }
Exemplo n.º 18
0
        private void createRolesAndUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();
            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("Admin"))
            {
                // first we create Admin role
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";


                //Here we create a Admin super user who will maintain the website
                ApplicationUser user = UserManager.FindByEmail("*****@*****.**");
                if (user != null)
                {
                    roleManager.Create(role);
                    var result1 = UserManager.AddToRole(user.Id, "Admin");
                }
            }
            // creating Creating Manager role
            if (!roleManager.RoleExists("Manager"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Manager";
                roleManager.Create(role);
            }

            // creating Creating Employee role
            if (!roleManager.RoleExists("Employee"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Employee";
                roleManager.Create(role);
            }
        }
Exemplo n.º 19
0
        // In this method we will create role Admin and Guest
        private void createRoles()
        {
            ApplicationDbContext context = new ApplicationDbContext();

            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("Admin"))
            {
                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                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 = "Daniel992`";

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

                //Add default User to Role Admin
                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Admin");
                }
            }
            // creating Creating Guest role
            if (!roleManager.RoleExists("Guest"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Guest";
                roleManager.Create(role);
            }
        }
Exemplo n.º 20
0
        //this method creates default User roles
        private void CreateRolesAndUsers()
        {
            ApplicationDbContext db = new ApplicationDbContext();

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


            //Creating Customer Role
            if (!roleManager.RoleExists("Patient"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Patient";
                roleManager.Create(role);
            }
            //Creating Employee Role
            if (!roleManager.RoleExists("Provider"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Provider";
                roleManager.Create(role);
            }
        }
Exemplo n.º 21
0
        private void CreateRolesAndUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

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

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

            // creating Creating Employee role
            if (!roleManager.RoleExists("Participant"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Participant";
                roleManager.Create(role);
            }
        }
Exemplo n.º 22
0
        private void createRolesandUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

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


            if (!roleManager.RoleExists("Admin"))
            {
                //Creates Admin roll
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

                //Populate Admin User
                var user = new ApplicationUser();
                user.UserName = "******";
                user.Email    = "*****@*****.**";

                string userPWD = "Password1!";

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

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

            if (!roleManager.RoleExists("User"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "User";
                roleManager.Create(role);
            }
        }
Exemplo n.º 23
0
        // In this method we will create a default user roles and admin user for login
        private void createRoleandUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

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

            // in starup iam creating first admin role and creating a default admin user
            if (!roleManager.RoleExists("Admin"))
            {
                //first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                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 = "carlos123";

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

                //add default User to role admin
                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Admin");
                }
            }

            // creating employee role
            if (!roleManager.RoleExists("Employee"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Employee";
                roleManager.Create(role);
            }
        }
Exemplo n.º 24
0
        private void CreateRolesAndUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

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

            if (!roleManager.RoleExists("AppManager"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "AppManager";
                roleManager.Create(role);

                //Contact developer for additional app manager sign ins



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

                string userPWD = "asdsasdA1!";

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

                if (chkUser.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "AppManager");
                }
            }

            if (!roleManager.RoleExists("Customer"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Customer";
                roleManager.Create(role);
            }
        }
Exemplo n.º 25
0
        public void  createRoles()
        {
            context = new ApplicationDbContext();
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));


            if (!roleManager.RoleExists("Admin"))
            {
                // first we create Admin rool
                var role = new IdentityRole();
                role.Name = "Admin";
                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 = "Temp@123";

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

                //Add default User to Role Admin
                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Admin");
                }
            }
            // creating Creating Other End User role
            if (!roleManager.RoleExists("Other"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Other";
                roleManager.Create(role);
            }
        }
Exemplo n.º 26
0
        protected override void Seed(Sentio.Models.ApplicationDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //


            if (context.Roles.Count() == 0)
            {
                var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
                var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
                var role        = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

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

                string userPW = "Eva123$";

                var adminUser = userManager.Create(user, userPW);

                if (adminUser.Succeeded)
                {
                    var result1 = userManager.AddToRole(user.Id, "Admin");
                }
            }
        }
Exemplo n.º 27
0
        private void CreateRolls()
        {
            ApplicationDbContext context = new ApplicationDbContext();

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

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

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

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

            if (!roleManager.RoleExists("Unknown"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Unknown";
                roleManager.Create(role);
            }
        }
Exemplo n.º 28
0
        private async System.Threading.Tasks.Task CreateDefaultRolesAsync()
        {
            ApplicationDbContext context = new ApplicationDbContext();

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

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

                //Here we create a SuperAdmin user who will maintain the website

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


                string userPWD = "Test123!!";

                var result = await UserManager.CreateAsync(user, userPWD);

                //Add default User to Role SuperAdmin
                if (result.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "Super Admin");
                }
            }
            if (!roleManager.RoleExists("Admin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);
            }
        }
Exemplo n.º 29
0
        private void CreateRolesAndUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));


            if (!roleManager.RoleExists("Admin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

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

                string userPWD = "Acer4060!";

                var chkUser = userManager.Create(user, userPWD);
                if (chkUser.Succeeded)
                {
                    var result1 = userManager.AddToRole(user.Id, "Admin");
                }
            }
            if (!roleManager.RoleExists("Moderator"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Moderator";
                roleManager.Create(role);
            }
            if (!roleManager.RoleExists("Customer"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Customer";
                roleManager.Create(role);
            }
        }
Exemplo n.º 30
0
        protected void CreateUser()
        {
            ApplicationDbContext _context = new ApplicationDbContext();

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

            var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(_context));

            if (!roleManager.RoleExists(MB.Admin))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = MB.Admin;

                roleManager.Create(role);

                var user = new ApplicationUser();

                user.UserName = "******";
                user.Email    = "*****@*****.**";

                user.user_Name   = "Admin";
                user.accountPass = "******";
                string userPass  = "******";
                var    checkUser = userManager.Create(user, userPass);
                if (checkUser.Succeeded)
                {
                    var result1 = userManager.AddToRole(user.Id, MB.Admin);
                }
            }

            if (!roleManager.RoleExists(MB.User))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = MB.User;

                roleManager.Create(role);
            }
        }
Exemplo n.º 31
0
        private void createRolesAndUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

            if (!roleManager.RoleExists("Admin"))
            {
                var     role    = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                Company company = new Company {
                    Name = "LiSaNa"
                };
                role.Name = "Admin";
                roleManager.Create(role);
                var user = new ApplicationUser();
                user.UserName = "******";
                user.Email    = "*****@*****.**";
                user.Company  = company;
                string userPWD   = "Test123!";
                var    checkUser = userManager.Create(user, userPWD);
                if (checkUser.Succeeded)
                {
                    var result1 = userManager.AddToRole(user.Id, "Admin");
                }
            }
            if (!roleManager.RoleExists("Admin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);
            }
            if (!roleManager.RoleExists("Employee"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Employee";
                roleManager.Create(role);
            }
        }
Exemplo n.º 32
0
        public void CreateRoles()
        {
            var roleManager = new RoleManager <Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));

            if (!roleManager.RoleExists("Admin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);
            }
            if (!roleManager.RoleExists("Manager"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Manager";
                roleManager.Create(role);
            }
            if (!roleManager.RoleExists("User"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "User";
                roleManager.Create(role);
            }
        }
Exemplo n.º 33
0
        public ActionResult Create(RoleCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            if (!roleManager.RoleExists("Admin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = model.Role;
                roleManager.Create(role);

                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.MSG = "Role Already Exists";
                return(View());
            }
        }
Exemplo n.º 34
0
        private void SeedRoles(AppContext context)
        {
            var roleManager = new RoleManager <Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore <IdentityRole>());

            if (!roleManager.RoleExists("Admin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);
            }
            if (!roleManager.RoleExists("Lider"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Lider";
                roleManager.Create(role);
            }
            if (!roleManager.RoleExists("Muzyk"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Muzyk";
                roleManager.Create(role);
            }
        }
        //Create default User roles and Admin user for login
        private void CreateRolesandUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();
            var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
            var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));

            // Creating first Admin Role and creating a default Admin User
            if (!roleManager.RoleExists("Admin"))
            {
                // Create Admin roll
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);
                // Create an Admin super user who will maintain the website

                        var user = new ApplicationUser();
                        user.UserName = "******";
                        user.FirstName = "Admin";
                        user.LastName = "RDCC";
                        user.EmailAddress = "*****@*****.**";

                        string userPWD = "Rdcc1234!";

                        var chkUser = userManager.Create(user, userPWD);
                        var adminRole = roleManager.FindByName("Admin");
                        //Add default User to Role Admin
                        if (chkUser.Succeeded)
                        {
                            var result1 = userManager.AddToRole(user.Id, "Admin");

                        }

            }

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

            }

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

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

            }

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

            }

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

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

            }

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

            }

            if (!roleManager.RoleExists("Publicity Officer"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Publicity Officer";
                roleManager.Create(role);

            }
        }
Exemplo n.º 36
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            using (var context = new ApplicationDbContext())
            {
                if (ModelState.IsValid)
                {
                    var user = new ApplicationUser() { UserName = model.UserName };
                    var result = await UserManager.CreateAsync(user, model.Password);

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

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

                    if (!roleManager.RoleExists("Admin"))
                    {
                        var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                        role.Name = "Admin";
                        roleManager.Create(role);
                    }

                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent: false);
                        userManager.AddToRole(user.Id, "Admin");
                        return RedirectToAction("Index", "Home");
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
                // If we got this far, something failed, redisplay form
                return View(model);
            }
        }