Public Class MyAccount
    Inherits System.Web.UI.Page

    Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try

            phAccountInfoSaved.Visible = False
            phChangePasswordSaved.Visible = False
            phInvalidPassword.Visible = False

            If Not Page.IsPostBack Then
                Dim acct = Master.CurrentClient
                txtUsername.Text = acct.username
                txtNameFirst.Text = acct.nameFirst
                txtNameMiddle.Text = acct.nameMiddle
                txtNameLast.Text = acct.nameLast
                txtEmail.Text = acct.email
            End If

        Catch ex As Exception
            Dim errorId = Logic.Error.Log(ex)
            Response.Redirect("/Error.aspx?id=" & errorId)
        End Try
    End Sub

    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click, btnCancel2.Click
        Response.Redirect("../Dashboard.aspx?cid=" & Request.Params("cid"))
    End Sub

    ' change password
    Private Sub btnChange_Click(sender As Object, e As EventArgs) Handles btnChange.Click
        If Not Page.IsValid() Then
            Exit Sub
        End If

        Try
            Dim acct = Master.CurrentClient
            acct.ChangePassword(txtNewPassword.Text)

            phChangePasswordSaved.Visible = True

        Catch ex As Exception
            Dim errorId = Logic.Error.Log(ex)
            Response.Redirect("/Error.aspx?id=" & errorId)
        End Try

    End Sub

    ' save account info
    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click, btnDefault.Click
        If Not Page.IsValid() Then
            Exit Sub
        End If

        Try
            Dim acct = Master.CurrentClient

            If acct.VerifyPassword(txtPassword.Text) = False Then
                phInvalidPassword.Visible = True
                Exit Sub
            End If

            acct.nameFirst = txtNameFirst.Text
            acct.nameMiddle = txtNameMiddle.Text
            acct.nameLast = txtNameLast.Text
            acct.nameSuffix = txtNameSuffix.Text
            acct.email = txtEmail.Text
            acct.Update()

            phAccountInfoSaved.Visible = True

        Catch ex As Exception
            Dim errorId = Logic.Error.Log(ex)
            Response.Redirect("/Error.aspx?id=" & errorId)
        End Try

    End Sub

End Class