Imports EDSL.Entities
Imports EDSL.DAL
Partial Public Class mainPageEditControl
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        txtPageContent.BaseHref = ConfigurationManager.AppSettings("BaseHref") & "PageEdit"
        txtPageContent.BasePath = ConfigurationManager.AppSettings("BasePath")
        If IsPostBack = False Then
            If Request.QueryString("id") = 0 OrElse Request.QueryString("id") = "" Then
            Else
                Call GetDetails(Request.QueryString("id"))
            End If
        End If
    End Sub
    Private Sub GetDetails(ByVal intLoginID As Integer)
        Dim objMain As New dbMainPage
        Dim objMainEntity As entMainPage = objMain.GetItem(intLoginID)
        txtID.Value = objMainEntity.PageID
        txtPageTitle.Text = objMainEntity.PageTitle
        txtPageContent.Value = objMainEntity.PageContent
        txtPageMetaName.Text = objMainEntity.PageMetaName
        txtPageMetaContent.Text = objMainEntity.PageMetaContent
        txtMetaTitle.Text = objMainEntity.MetaTitle
        If objMainEntity.MainImage = "" Then
            imgMainImage.ImageUrl = ConfigurationManager.AppSettings("BaseHref") & "images/noimage.png"
        Else
            Dim strUploadPath As String = ConfigurationManager.AppSettings("UploadFileURL") & "images/"
            imgMainImage.ImageUrl = strUploadPath & objMainEntity.MainImage
            txtMainImage.Value = objMainEntity.MainImage
        End If
    End Sub
    Protected Sub btnSave_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
        Dim clsMisc As New miscFunctions
        Dim objGlobals As New TheGlobals
        Dim objMainAdmin As New dbMainPage
        Dim intResultFromSave As Integer
        Dim intID As Integer
        If txtID.Value = "" Then
            intID = 0
        Else
            intID = CInt(txtID.Value)
        End If

        Dim strFileName As String
        Dim booTryToSave As Boolean = False
        If chkRemoveImage.Checked = True Then
            strFileName = ""
            booTryToSave = True
        Else
            strFileName = clsMisc.UploadFile(filMainImage, objGlobals.UploadFileTypes.Image)

            If strFileName = "" Then
                strFileName = txtMainImage.Value
                booTryToSave = True
            ElseIf Left(strFileName, 17) = "EdenlightError:::" Then
                divErrorPanel.InnerHtml = Right(strFileName, Len(strFileName) - 17)
                booTryToSave = False
            Else
                booTryToSave = True
            End If
        End If

        If booTryToSave = True Then
            intResultFromSave = objMainAdmin.SaveItem(intID, txtPageTitle.Text, txtPageContent.Value.ToString(), txtPageMetaName.Text, txtPageMetaContent.Text, txtMetaTitle.Text, strFileName, Session("passover"))
            Select Case intResultFromSave
                Case 0
                    Response.Redirect("mainPagelist.aspx")
                Case 1
                    divErrorPanel.InnerHtml = "Error saving page details"
                Case Else
                    Response.Redirect("mainPagelist.aspx")
            End Select
        End If
    End Sub
    Protected Sub btnBack_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnBack.Click
        Response.Redirect("mainPagelist.aspx")
    End Sub
End Class
