Exemplo n.º 1
0
        /// <summary>
        /// Inserts a new Role in the Roles table
        /// </summary>
        /// <param name="roleName">The role's name</param>
        /// <returns></returns>
        public int Insert(IdentityRole role)
        {
            string commandText = "Insert into Roles (Id, Name) values (@id, @name)";
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("@name", role.Name);
            parameters.Add("@id", role.Id);

            return _database.Execute(commandText, parameters);
        }
        /// <summary>
        /// Gets the IdentityRole given the role name
        /// </summary>
        /// <param name="roleName"></param>
        /// <returns></returns>
        public IdentityRole GetRoleByName(string roleName)
        {
            var roleId = GetRoleId(roleName);
            IdentityRole role = null;

            if (roleId != null)
            {
                role = new IdentityRole(roleName, roleId);
            }

            return role;
        }
        public int Update(IdentityRole role)
        {
            string commandText = "Update Roles set Name = @name where Id = @id";
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("@id", role.Id);

            return _database.Execute(commandText, parameters);
        }
        public async Task<ActionResult> CreateRole()
        {
            var role = new IdentityRole() { Name = "Admin" };
            var roleManger = await RoleManager.CreateAsync(role);


            //roleManger.CreateAsync(role);

            return View("ResetPassword");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the IdentityRole given the role Id
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public IdentityRole GetRoleById(int roleId)
        {
            var roleName = GetRoleName(roleId);
            IdentityRole role = null;

            if (roleName != null)
            {
                role = new IdentityRole(roleName, roleId);
            }

            return role;

        }
Exemplo n.º 6
0
        public IEnumerable<IdentityRole> GetAllRoles()
        {
            List<IdentityRole> roles = new List<IdentityRole>();
            string commandText = "Select * from Roles ";


            var rows = _database.Query(commandText);
            foreach (var row in rows)
            {
                var identityRole = new IdentityRole();
                identityRole.Id = Int32.Parse(row["Id"]);
                identityRole.Name = row["Name"];

                roles.Add(identityRole);
            }

            return roles;
        }
Exemplo n.º 7
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));
            var branchManager = new BranchManager <IdentityBranch>(new BranchStore <IdentityBranch>(context));
            var bankManager   = new BankManager <IdentityBank>(new BankStore <IdentityBank>(context));

            var user = new ApplicationUser();

            //branchManager.CreateUploadStatus();
            if (!roleManager.RoleExists("Admin"))
            {
                var role = new AspNet.Identity.MySQL.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

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

                string userPWD = "password77$";

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

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

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

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

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

            if (!branchManager.BranchExists("Head Office"))
            {
                user = UserManager.FindByName("administrator");

                var bank = new AspNet.Identity.MySQL.IdentityBank();
                bank.Name = ConfigurationManager.AppSettings["OwnerBankName"];
                bankManager.Create(bank);

                var branch = new AspNet.Identity.MySQL.IdentityBranch();
                branch.Name       = "Head Office";
                branch.BranchCode = "HeadOffice";
                //branch.GLAccount = ConfigurationManager.AppSettings["DefaultGLAccount"];
                branchManager.Create(branch);
                branchManager.AddUserToBranch(user.Id, branch.Id);
                //branchManager.CreateUploadStatus();
            }
        }