Imports System.Web.HttpContext
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.WebSite.Library
Imports System.Web


Public Class OrderManager

    Private _trackingID As String
    Private _om As BLOrderManager

    Private Sub New()
        _om = New BLOrderManager()

        _trackingID = HttpContext.Current.Session.SessionID


        'Try
        '  Common.RegisterChannels()
        '  OrderManagerProxy = CType(Activator.GetObject(GetType(OrderClient), CStr(HttpContext.Current.Application("RemoteURL_OrderManager"))), OrderClient)
        '  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 BLOrderManager
        Get
            Return _om
        End Get
        Set(ByVal value As BLOrderManager)
            _om = value
        End Set
    End Property

    ' returns an instance of Account Manager
    Public Shared Function Instance() As OrderManager
        Try
            'If Common.RetriveFromSession(Common.OrderManagerKey) Is Nothing Then
            '  'If user instance does not exist, create one
            '  Common.AddToSession((Common.OrderManagerKey), New OrderManager())
            '  Return CType(Common.RetriveFromSession(Common.OrderManagerKey), OrderManager)
            'Else
            '  'If user instance already exists, return that
            '  Return CType(Common.RetriveFromSession(Common.OrderManagerKey), OrderManager)
            'End If
            Return New OrderManager
        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

    ' this method should be used to submit an order, if credit card information is available
    'Public Function SubmitOrder(ByVal amount As Decimal, ByVal name As String, ByVal type As BL.Entities.CreditCardType, ByVal number As String, ByVal expMonth As String, ByVal expYear As String) As Boolean
    '  Try

    '    Return OrderManagerProxy.SubmitOrder(TrackingID, amount, name, type.ToString(), number, expMonth, expYear)
    '  Catch ex As Exception
    '    Throw ex
    '  End Try

    'End Function

    'Public Function CancelOrder(ByVal orderConfirmation As String, ByVal reason As String) As Boolean
    '  Try
    '    'Return OrderManagerProxy.CancelOrder(TrackingID, orderConfirmation, reason)
    '  Catch ex As Exception
    '    Throw ex
    '  End Try
    'End Function

    Public Function GetOrderConfirmations() As Dictionary(Of Category, IOrder.IOrderConfirmation)

        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 IOrder.ISchedule, ByRef schedule2 As IOrder.ISchedule)
        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, IOrder.IAppointment))
        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


    Public Function SendELOA(ByVal userIDField As String, ByVal passwordField As String, ByVal eLOANameField As String, ByVal versionField As String, ByVal dNISField As String, ByVal telephoneNbrField As String, ByVal firstNameField As String, ByVal lastNameField As String, ByVal affiliateIDField As String, ByVal affiliateNameField As String, ByVal affiliateTypeField As String, ByVal decisionMakerField As String, ByVal securityTypeField As String, ByVal securityValueField As String, ByVal localField As String, ByVal localTollField As String, ByVal longDistanceField As String, ByVal e911Field As String, ByVal statusField As String, ByVal reasonCodeField As String, ByVal wTNsField() As String) As Boolean
        Try
            Return OrderManagerProxy.SendELOA(TrackingID, userIDField, passwordField, eLOANameField, versionField, dNISField, telephoneNbrField, firstNameField, lastNameField, affiliateIDField, affiliateNameField, affiliateTypeField, decisionMakerField, securityTypeField, securityValueField, localField, localTollField, longDistanceField, e911Field, statusField, reasonCodeField, wTNsField)
        Catch ex As Exception
            Throw ex
        End Try
    End Function

End Class
