I have done exactly this. Theres a lot of code but youll see what I did
Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
If AddUser Then
If IsValid Then
Dim createStatus As UserCreateStatus = CreateUser()
AddUserToRoles(createStatus)
UserCreateCompleted(createStatus)
End If
Else
If ((UserEditor.IsValid) Or (ProfileProperties.IsValid)) AndAlso (Not User Is Nothing) Then
User.Membership.UpdatePassword = False
UserController.UpdateUser(PortalId, User)
End If
AddUserToRoles()
End If
End Sub
IsValid is copied straight from the DNN core code. Adduser is a DNN property.
I then used CreateUser
Public Function CreateUser() As UserCreateStatus
User.Membership.Approved = False
If User.Profile.LastName = Null.NullString Then
User.Profile.LastName = User.LastName
End If
If User.Profile.FirstName = Null.NullString Then
User.Profile.FirstName = User.FirstName
End If
User.Profile.SetProfileProperty("AFLTeam", ddlSportTeams.SelectedItem.Text)
Return UserController.CreateUser(User)
End Function
Then
Private Sub UserCreateCompleted(ByVal CreateStatus As UserCreateStatus)
Dim strMessage As String = ""
Try
If CreateStatus = UserCreateStatus.Success Then
'Do what you need here
And I have a new routine to add the roles to users wher I have a grid of services they can click a checkbox on.
Private Sub AddUserToRoles()
Dim objRoles As New RoleController
Dim Selected As System.Web.UI.WebControls.CheckBox
Dim intRow As Integer
Dim DI As DataGridItem
Dim TC As TableCell
Dim RoleId As Integer
For intRow = 0 To grdServices.Items.Count - 1
DI = grdServices.Items.Item(intRow)
TC = DI.Cells(0)
Selected = TC.FindControl("chkService")
If Selected.Checked = True Then
RoleId = CInt(DI.Cells(1).Text)
Dim objRole As RoleInfo = objRoles.GetRole(RoleId, PortalSettings.PortalId)
If objRole.IsPublic And objRole.ServiceFee = 0.0 Then
objRoles.UpdateUserRole(PortalId, User.UserID, RoleId, False)
End If
Else
RoleId = CInt(DI.Cells(1).Text)
Dim objRole As RoleInfo = objRoles.GetUserRole(PortalId, User.UserID, RoleId)
If Not objRole Is Nothing Then
objRoles.DeleteUserRole(PortalId, User.UserID, RoleId)
End If
End If
Next
End Sub
Uses all DNN objects and no custom SQL at all. :) Works great too.