Imports EDSL.Entities
Imports EDSL.DAL
Public Partial Class MessageEdit
  Inherits BasePage
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim objMainPage As New dbmainPage
    Dim objMainPageEntity As New entMainPage

    objMainPageEntity = objMainPage.GetPageDetails("MessageAdminEdit")
    Me.Title = ConfigurationManager.AppSettings("BrowserTitleCompanyName") & objMainPageEntity.PageTitle
    divContent.InnerHtml = objMainPageEntity.PageContent
    Me.MetaName = objMainPageEntity.PageMetaName
    Me.MetaContent = objMainPageEntity.PageMetaContent

    txtMessageText.BaseHref = ConfigurationManager.AppSettings("BaseHref") & "MessageAdmin"
    txtMessageText.BasePath = ConfigurationManager.AppSettings("BasePath")
    If IsPostBack = False then
      If Request.QueryString("id") = 0 orelse Request.QueryString("id") = "" Then
        txtMessageName.Enabled = True
      else
        txtMessageName.Enabled = False
        call GetDetails(Request.QueryString("id"))
      End If
    End If
  End Sub
  Private sub GetDetails(byval intID As Integer)
    Dim objMain As new dbmainMessage
    Dim objMainEntity As entMainMessage = objMain.GetItem(intID)
    txtID.Value = objMainEntity.MessageID
    txtMessageName.Text = objMainEntity.MessageDesc
    txtMessageText.Value = objMainEntity.MessageText
  End sub
  Protected Sub btnSave_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
    Dim objMainAdmin As new dbmainMessage
    Dim intResultFromSave As Integer
    Dim intID As Integer
    If txtID.Value = "" then
      intID = 0
    else 
      intID = cint(txtID.Value)
    End If
    
    intResultFromSave = objMainAdmin.SaveItem(intID, txtMessageText.Value.ToString, session("passover"))
    Select Case intResultFromSave 
      Case 0
        Response.Redirect("list.aspx")
      Case 1
        divErrorPanel.InnerHtml = "Error saving message"
      Case 2
        divErrorPanel.InnerHtml = "Messagename already exists"
      Case Else
        Response.Redirect("list.aspx")
    End Select
  End Sub
  Protected Sub btnBack_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnBack.Click
    Response.Redirect("list.aspx")
  End Sub
End Class