Imports EDSL.Entities
Imports EDSL.DAL
Public Partial Class NLEditControl
  Inherits System.Web.UI.UserControl
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If IsPostBack = False then
      If Request.QueryString("id") = 0 orelse Request.QueryString("id") = "" Then
        btnDelete.Visible = False
      else
        btnDelete.Visible = true
        call GetDetails(Request.QueryString("id"))
      End If
    End If
  End Sub
  Private sub GetDetails(byval intLoginID As Integer)
    Dim objMain As new dbMainNLR
    Dim objMainEntity As entMainNewsLetterRecipients = objMain.GetItem(intLoginID)
    txtID.Value = objMainEntity.NLRID
    txtName.Value = objMainEntity.RecipientName
    txtEmail.Text = objMainEntity.RecipientEmail
  End sub
  Protected Sub btnDelete_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnDelete.Click
    Dim objMain As new dbMainNLR
    Response.Redirect("Delete.aspx?id=" & txtID.Value & "&idtext=" & txtEmail.Text & "&r=e")
  End Sub
  Protected Sub btnSave_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
    Dim objMain As new dbMainNLR
    Dim intResultFromSave As Integer
    Dim intID As Integer
    If txtID.Value = "" then
      intID = 0
    else 
      intID = cint(txtID.Value)
    End If

    intResultFromSave = objMain.SaveItem(intID, txtName.Value, txtEmail.Text, session("passover"))
    Select Case intResultFromSave 
      Case 0
        Response.Redirect("List.aspx")
      Case 1
        divErrorPanel.InnerHtml = "Error saving newsletter recipient details"
      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
