예제 #1
0
        protected void UserRoleGridview_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int         index        = Convert.ToInt32(e.CommandArgument);
            GridViewRow row          = UserRoleGridview.Rows[index];
            var         _roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext()));
            var         _userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(new ApplicationDbContext()));

            if (e.CommandName == "AddAdmin")
            {
                _userManager.RemoveFromRole(row.Cells[0].Text, row.Cells[3].Text);
                _userManager.AddToRole(row.Cells[0].Text, "Admin");
            }
            if (e.CommandName == "AddTeacher")
            {
                _userManager.RemoveFromRole(row.Cells[0].Text, row.Cells[3].Text);
                _userManager.AddToRole(row.Cells[0].Text, "Teacher");
            }
            if (e.CommandName == "AddUser")
            {
                _userManager.RemoveFromRole(row.Cells[0].Text, row.Cells[3].Text);
                _userManager.AddToRole(row.Cells[0].Text, "User");
            }

            UserRoleGridview.DataSource = getRoles();
            UserRoleGridview.DataBind();
        }
예제 #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         UserRoleGridview.DataSource = getRoles();
         UserRoleGridview.DataBind();
     }
 }