Exemplo n.º 1
0
        public bool Seed(EasyContext context)
        {
            bool success     = false;
            var  roleManager = new ApplicationRoleManager(new RoleStore <ApplicationRole>(context));

            if (!roleManager.RoleExists("Super Admin"))
            {
                success = this.CreateRole(roleManager, "Super Admin", "Easy Sale Autority");
            }
            if (!success == true)
            {
                return(false);
            }
            if (!roleManager.RoleExists("Admin"))
            {
                success = this.CreateRole(roleManager, "Admin", "Edit existing records");
            }

            if (!success == true)
            {
                return(false);
            }

            if (!roleManager.RoleExists("User"))
            {
                success = this.CreateRole(roleManager, "User", "Restricted to business domain activity");
            }
            if (!success)
            {
                return(false);
            }


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

            var user           = new ApplicationUser();
            var passwordHasher = new PasswordHasher();

            user.UserName = "******";
            user.FullName = "Md. Rakibul Islam Biplob";


            if (!context.Users.Any(u => u.UserName == user.UserName))
            {
                IdentityResult result = userManager.Create(user, "Test@123");
            }

            success = this.AddUserToRole(userManager, user.Id, "Admin");
            if (!success)
            {
                return(false);
            }

            success = this.AddUserToRole(userManager, user.Id, "Super Admin");
            if (!success)
            {
                return(false);
            }

            success = this.AddUserToRole(userManager, user.Id, "User");
            if (!success)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public bool CreateRole(ApplicationRoleManager _roleManager, string name, string description = "")
        {
            var idResult = _roleManager.Create <ApplicationRole, string>(new ApplicationRole(name, description));

            return(idResult.Succeeded);
        }