﻿Imports com.racadtech.Framework.Database
Imports com.racadtech.Framework.Web.Security

Partial Class order_centre_new_user
    Inherits System.Web.UI.Page

    Private _webUserControl As New com.racadtech.Framework.Web.Security.UserControl()
    Public ReadOnly Property ErrorMessage() As String
        Get
            If (Session("NewUser.ErrorMessage") Is Nothing) Then
                Return ""
            Else
                Return Session("NewUser.ErrorMessage")
            End If
        End Get
    End Property

    Public ReadOnly Property DatabaseInstance() As Database
        Get
            Return DatabaseManager.CreateDatabase("PrintIt")
        End Get
    End Property

    Public ReadOnly Property WebUserContorl() As com.racadtech.Framework.Web.Security.UserControl
        Get
            Return _webUserControl
        End Get
    End Property

    Public ReadOnly Property MembershipProviderInstance() As MembershipProvider
        Get
            Return Membership.Provider
        End Get
    End Property

    Public ReadOnly Property RoleProviderInstance() As RoleProvider
        Get
            Return Roles.Provider
        End Get
    End Property

    Protected Sub CreateNewUserImageButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles CreateNewUserImageButton.Click
        Dim _userDetails As UserDetails = WebUserContorl.CreateUser(MembershipProviderInstance, _
                                  RoleProviderInstance, UserNameTextBox.Text.ToString(), _
                                  PasswordTextBox.Text.ToString(), EmailTextBox.Text.ToString(), "PrintItWebCustomer")

        If (_userDetails.ErrorCode > 0) Then ' Failed
            Session("NewUser.ErrorMessage") = _userDetails.ErrorMessage
            Response.Redirect("~/order_centre/new_user.aspx")
        Else
            FormsAuthentication.SetAuthCookie(UserNameTextBox.Text.ToString(), True)
            Dim _userProfile As ProfileCommon

            _userProfile = ProfileCommon.Create(UserNameTextBox.Text.ToString())
            _userProfile.StoreId = 999999
            _userProfile.Save()
            Response.Redirect("~/order_centre/customer_contact_info.aspx")
        End If

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ErrorLabel.Text = ErrorMessage
    End Sub
End Class
