Imports System.Collections.Generic
Imports CharterDotCom.CommonEntities.Library
Imports CharterDotCom.CommonEntities.Library.Common
Imports CharterDotCom.CommonEntities.Library.Enumerations
Imports CharterDotCom.CommonEntities.Library.EntityMemberServices
Imports CharterDotCom.CommonEntities.Library.EntityEBSServices
Imports CharterDotCom.CommonEntities.Library.EntitySupport
Imports CharterDotCom.CommonEntities.Library.EntitySearch
Imports CharterDotCom.CommonEntities.Library.EntityWebConfig
Imports CharterDotCom.CommonEntities.Library.EntityG2BServices
Imports CharterDotCom.WebSite.Library
Imports CharterDotCom.WebSite.Library.BLCommon

Partial Class Order_AffiliateOfferDetail
    Inherits CharterCMSPage


    Public ReadOnly Property SelectedItemID() As Integer
        Get
            If Request.Form("txtAddItem") Is Nothing Or Request.Form("txtAddItem") = String.Empty Then
                Return 0
            Else
                Return CType(Request.Form("txtAddItem"), Integer)
            End If
        End Get
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SetPageTitle("Offer Detail")
        If SelectedItemID > 0 Then
            AffliateCatalogManager.Instance.AddCartItem(SelectedItemID, New Notify(AddressOf ucShoppingCart.OnNotification))
        End If
    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        Dim catalog As ICatalog
        Dim offerID As String
        Dim offer As ICartItem

        Me.ucShoppingCart.HBXInfo_PageName = "OfferDetail"
        Me.ucShoppingCart.HBXInfo_MLC = "OfferDetail"

        offerID = 0
        offer = Nothing

        If Not IsPostBack Then
            If Not (Request.QueryString(QueryStringName.OfferID) Is Nothing) Then
                offerID = Request.QueryString(QueryStringName.OfferID)
            End If
        Else
            If Not (Request.QueryString(QueryStringName.OfferID) Is Nothing) Then
                offerID = Request.QueryString(QueryStringName.OfferID)
                'offerID = SelectedItemID
            End If
        End If

        If offerID > 0 Then
            catalog = AffliateCatalogManager.Instance.GetCatalog()

            If catalog Is Nothing Then
                Throw New MissingCatalogException()
            End If

            ' assign shopping cart's cart property
            ucShoppingCart.Cart = catalog.Cart

            If catalog.Bundles.ContainsKey(offerID) Then
                offer = catalog.Bundles(offerID)
            ElseIf catalog.ServicePlans.ContainsKey(offerID) Then
                offer = catalog.ServicePlans(offerID)
            End If
        End If

        If offer Is Nothing Then
            ucOfferDetail.Visible = False
        Else
            '9/18/2007 Brad Miller - Populate Contract properties for G2B 4.1
            ucOfferDetail.OfferID = offer.ID
            ucOfferDetail.OfferName = offer.Name
            ucOfferDetail.OfferPrice = offer.Price
            ucOfferDetail.OfferType = offer.Type
            ucOfferDetail.IsAvailable = offer.IsAvailable

            If offer.ContractDescription IsNot Nothing AndAlso offer.ContractDescription <> String.Empty Then
                ucOfferDetail.ContractDescription = offer.ContractDescription
            End If
            If offer.ContractTermsAndConditions IsNot Nothing AndAlso offer.ContractTermsAndConditions <> String.Empty Then
                ucOfferDetail.ContractTermsAndConditions = offer.ContractTermsAndConditions
            End If
            If offer.Requirements IsNot Nothing AndAlso offer.Requirements <> String.Empty Then
                ucOfferDetail.Requirements = offer.Requirements
            End If

            ucOfferDetail.NationalPrice = offer.ListPrice
            ucOfferDetail.Disclaimer = offer.PromotionDisclaimer
            ucOfferDetail.Visible = True
            ucOfferDetail.OfferContent = offer.MarketingInfo
        End If
    End Sub
End Class