예제 #1
0
        private void createRolesandUsers(string username, string userType)
        {
            ApplicationDbContext context = new ApplicationDbContext();

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


            if (!roleManager.RoleExists("Employee") && userType == "1")
            {
                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Employee";
                roleManager.Create(role);
            }
            if (!roleManager.RoleExists("Customer") && userType == "2")
            {
                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Customer";
                roleManager.Create(role);
            }
            string s;

            if (userType == "1")
            {
                s = "Employee";
            }
            else
            {
                s = "Customer";
            }
            var result1 = UserManager.AddToRole(username, s);
        }
예제 #2
0
        // In this method we will create default User roles and Admin user for login
        private void createRolesandUsers()
        {
            Models.ApplicationDbContext context = new ApplicationDbContext();

            var roleManager = new Microsoft.AspNet.Identity.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 = "P@ssw0rd";

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

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

            // creating Creating Manager role
            if (!roleManager.RoleExists("User"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "User";
                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);
            }
        }
예제 #3
0
        public void createRole()
        {
            var          manger = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db));
            IdentityRole role   = new IdentityRole();

            if (!manger.RoleExists("Admin"))
            {
                role.Name = "Admin";
                manger.Create(role);
            }
            if (!manger.RoleExists("User"))
            {
                role.Name = "User";
                manger.Create(role);
            }
        }
예제 #4
0
        private void CreateRolesAndUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

            var roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new Microsoft.AspNet.Identity.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);

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

                string userPWD = "HuaTheDogN0se!";

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


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

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

            // creating Creating Employee role
            if (!roleManager.RoleExists("Customer"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Customer";
                roleManager.Create(role);
            }
        }
예제 #5
0
        private void CreateRoles()
        {
            ApplicationDbContext context = new ApplicationDbContext();
            var roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

            if (!roleManager.RoleExists("Visitor"))
            {
                var role = new IdentityRole();
                role.Name = "Visitor";
                roleManager.Create(role);
            }
            if (!roleManager.RoleExists("Admin"))
            {
                var role = new IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);
            }
        }
예제 #6
0
        private void CreateRole(WebShopContext context, string roleName)
        {
            var roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(
                new RoleStore <IdentityRole>(context));

            var result = roleManager.Create(new IdentityRole(roleName));

            if (!result.Succeeded)
            {
                throw new Exception(string.Join(";", result.Errors));
            }
        }
예제 #7
0
        public ActionResult AddRole(string RoleName)
        {
            var          roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db));
            IdentityRole role        = new IdentityRole();

            if (!roleManager.RoleExists(RoleName))
            {
                role      = new IdentityRole();
                role.Name = RoleName;
                roleManager.Create(role);
            }
            return(RedirectToAction("CreateRoles"));
        }
예제 #8
0
        public ActionResult CreateRole(FormCollection form)
        {
            ViewBag.RoleUyari = "";
            string RoleName    = form["RoleName"];
            var    roleManager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

            if (!roleManager.RoleExists(RoleName))
            {
                var role = new IdentityRole(RoleName);
                roleManager.Create(role);
            }
            else
            {
                ViewBag.RoleUyari = "The role you want to add is already registered.";
                return(View());
            }
            return(View());
        }
예제 #9
0
        private void createRolesandUsers(string username)
        {
            ApplicationDbContext context = new ApplicationDbContext();

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


            // In Startup iam creating first Admin Role and creating a default Admin User
            if (!roleManager.RoleExists("Administrator"))
            {
                // first we create Admin rool
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Administrator";
                roleManager.Create(role);
            }
            var result1 = UserManager.AddToRole(username, "Administrator");
        }
        protected override void  Seed(TrainerClientADOnet.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.


            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Admin"
                };

                manager.Create(role);
            }



            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <ApplicationUser>(context);
                var manager = new Microsoft.AspNet.Identity.UserManager <ApplicationUser>(store);
                var user    = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**"
                };

                manager.Create(user, "Teodora!1");
                context.Users.Add(user);
                manager.AddToRole(user.Id, "Admin");
            }


            //   if (!context.Roles.Any(u => u.Name == "Trener"))
            //   {
            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <ApplicationUser>(context);
                var manager = new Microsoft.AspNet.Identity.UserManager <ApplicationUser>(store);
                var user    = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**"
                };

                manager.Create(user, "Teodora!1");
                context.Users.Add(user);
                manager.AddToRole(user.Id, "Trener");
            }
            //  }



            if (!context.Roles.Any(u => u.Name == "Trener"))
            {
                if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
                {
                    var store   = new UserStore <ApplicationUser>(context);
                    var manager = new Microsoft.AspNet.Identity.UserManager <ApplicationUser>(store);
                    var user    = new ApplicationUser {
                        UserName = "******", Email = "*****@*****.**"
                    };

                    manager.Create(user, "Teodora!1");
                    context.Users.Add(user);
                    manager.AddToRole(user.Id, "Trener");
                }
            }

            /////////////////////
            ///

            if (!context.Roles.Any(r => r.Name == "Klijent"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new Microsoft.AspNet.Identity.RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Klijent"
                };

                manager.Create(role);
            }



            if (!context.Users.Any(u => u.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <ApplicationUser>(context);
                var manager = new Microsoft.AspNet.Identity.UserManager <ApplicationUser>(store);
                var user    = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**"
                };

                manager.Create(user, "Teodora!1");
                context.Users.Add(user);
                manager.AddToRole(user.Id, "Klijent");
            }
        }