コード例 #1
0
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        UserBLL  userBLL  = new UserBLL();
        RoleBLL  roleBLL  = new RoleBLL();
        GroupBLL groupBLL = new GroupBLL();

        string UserName = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName")).Text;
        int    roleID   = Convert.ToInt32(((DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlRoles")).SelectedValue);
        int    groupID  = Convert.ToInt32(((DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlGroups")).SelectedValue);

        Role  role  = roleBLL.GetRoleByRoleID(roleID);
        User  user  = userBLL.GetUserByUserName_WithoutApplication(UserName);
        Group group = groupBLL.GetGroupByGroupID(groupID);

        roleBLL.AddUserToRole(user, role);
        groupBLL.AddUserToGroup(user, group);

        Label lblEmail    = (Label)CompleteWizardStep1.ContentTemplateContainer.FindControl("lblEmail");
        Label lblUserType = (Label)CompleteWizardStep1.ContentTemplateContainer.FindControl("lblUserType");
        Label lblGroup    = (Label)CompleteWizardStep1.ContentTemplateContainer.FindControl("lblGroup");

        lblEmail.Text    = UserName;
        lblUserType.Text = ((DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlRoles")).SelectedItem.Text;
        lblGroup.Text    = ((DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlGroups")).SelectedItem.Text;

        Response.Redirect("~/secured/admin/users.aspx", true);
    }