Imports System.Web
Imports CharterDotCom.CommonEntities.Library
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 System.Configuration
Imports System.Runtime.Remoting
'Imports CharterDotCom.Library

Public Class AffiliateOrderManager

    Private _trackingID As String
    'Private _om As AffiliateOrderClient
    Private _om As BLAffiliateOrderManager

    Private Sub New()
    Dim cmSession As Object = HttpContext.Current.Session("AffiliateOrderManagerKey")
    If Not cmSession Is Nothing Then
      _om = New BLAffiliateOrderManager(DirectCast(cmSession, Dictionary(Of String, Object)))
    Else
      _om = New BLAffiliateOrderManager
    End If

        _trackingID = HttpContext.Current.Session.SessionID

        'Try
        '  Common.RegisterChannels()
        '  OrderManagerProxy = CType(Activator.GetObject(GetType(AffiliateOrderClient), CStr(HttpContext.Current.Application("RemoteURL_AffiliateOrderManager"))), AffiliateOrderClient)
        '  If Not HttpContext.Current.Request.Cookies(CookieName.SessionID) Is Nothing Then
        '    _trackingID = OrderManagerProxy.Initialize(HttpContext.Current.Request.Cookies(CookieName.SessionID).Value)
        '  Else
        '    _trackingID = OrderManagerProxy.Initialize(Nothing)
        '    HttpContext.Current.Response.Cookies.Add(New HttpCookie(CookieName.SessionID, TrackingID))
        '  End If
        'Catch ex As Exception
        '  Throw ex
        'End Try
    End Sub

    'Public Sub Destory()
    '    Try
    '        OrderManagerProxy.Destroy(TrackingID)
    '    Catch ex As Exception
    '        Throw ex
    '    End Try
    'End Sub

    Friend ReadOnly Property TrackingID() As String
        Get
            Return _trackingID
        End Get
    End Property

    Friend Property OrderManagerProxy() As BLAffiliateOrderManager
        Get
            Return _om
        End Get
        Set(ByVal value As BLAffiliateOrderManager)
            _om = value
        End Set
    End Property

    Public Shared Function Instance() As AffiliateOrderManager
        Try
            Return New AffiliateOrderManager
        Catch ex As Exception
            Throw ex
        End Try
    End Function


#Region "Order"

    ' this method should be used to submit an order, if credit card information is not avaialable
    Public Function SubmitOrder() As Boolean
        Try
            Return OrderManagerProxy.SubmitOrder(TrackingID)
        Catch ex As Exception
            Throw ex
        End Try

    End Function

    Public Function GetOrderConfirmations() As List(Of IAffiliateOrder.IAffiliateOrderConfirmation)

        Try

            Return OrderManagerProxy.GetOrderConfirmations(TrackingID)

        Catch ex As Exception

            Throw ex

        End Try

    End Function


    Public Sub GetConfirmationInfo(ByRef list As Dictionary(Of String, IConfirmation))
        Try

            OrderManagerProxy.GetConfirmationInfo(TrackingID, list)

        Catch ex As Exception

            Throw ex

        End Try
    End Sub

#End Region

#Region "Schedule"

    ' this method returns the available schedules for cable, hsd and Telephone categories 
    Public Sub GetSchedule(ByRef schedule1 As IAffiliateOrder.IAffiliateSchedule, ByRef schedule2 As IAffiliateOrder.IAffiliateSchedule)
        Try
            OrderManagerProxy.GetSchedule(TrackingID, schedule1, schedule2)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Function SubmitSchedules(ByVal type1 As String, ByVal schedule1 As List(Of String), ByVal type2 As String, ByVal schedule2 As List(Of String)) As Boolean
        Try
            OrderManagerProxy.SubmitSchedules(TrackingID, type1, schedule1, type2, schedule2)
        Catch ex As Exception
            Throw ex
        End Try
    End Function

#End Region

#Region "Appointments"

    Public Sub GetAppointments(ByRef list As Dictionary(Of ScheduleType, IAffiliateOrder.IAffiliateAppointment))
        Try
            OrderManagerProxy.GetAppointments(TrackingID, list)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

#End Region

#Region "FINISH ORDER"

    Public Sub ClearShoppingCart()
        Try
            OrderManagerProxy.ClearShoppingCart(TrackingID)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Sub SendOrderConfirmationEmail()
        Try
            OrderManagerProxy.SendOrderConfirmationEmail(TrackingID)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

#End Region


End Class
