Imports System.Web
Imports System.Xml
Imports System.Net
Imports CharterDotCom.CommonEntities.Library
Imports CharterDotCom.CommonEntities.Library.CouponServices
' Imports CharterDotCom.Common.Logging

''' ----------------------------------------------------------------------------
''' <summary>
''' 
'''     Project:  CouponProvider
'''       Class:  ProviderManager
''' 
''' Description:  Provider class for calling Coupon Management System Web
'''               services.
''' 
''' </summary>
''' <remarks></remarks>
''' <history>
''' 	[jnaes]		11/22/2010	Issue #10934.  Added gift card lookup.
''' 	[jnaes]		11/23/2010	Issue #10934.  Refactored coupon redemption.
''' 	[jnaes]		11/26/2010	Issue #10934.  Added gift card redemption.
''' 	[jnaes]		01/05/2011	Issue #10934.  Added address retrieval.
''' </history>
''' ----------------------------------------------------------------------------
Public Class ProviderManager
    Inherits ICouponProvider

    Private wsRedeemCouponService As WSRedemptionServiceRedeem.RedemptionService
    Private wsCouponStatusService As WSRedemptionServiceStatus.CouponStatusService
    Private wsCustomerRedemptionHistoryService As WSRedemptionServiceHistory.RedemotionHistoryService

#Region "RedemptionService Property"

    ''' ------------------------------------------------------------------------
    ''' <summary>
    ''' 
    '''    Property:  RedemptionService
    ''' 
    ''' Description:  Returns an object for the Coupon Redemption Web service.
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' ------------------------------------------------------------------------
    Private ReadOnly Property RedemptionService() As WSRedemptionServiceRedeem.RedemptionService
        Get

            If Me.wsRedeemCouponService Is Nothing Then

                Dim context As HttpContext = HttpContext.Current

                '---------------------------------------------------------------
                ' Create new Web service object and assign URL.
                '---------------------------------------------------------------
                Dim uri As New Uri(context.Application(Constant.COUPONSERVICESPROVIDER_REDEEMWEBSERVICE_URL))

                Me.wsRedeemCouponService = New WSRedemptionServiceRedeem.RedemptionService
                Me.wsRedeemCouponService.Url = uri.AbsoluteUri

                '---------------------------------------------------------------
                ' Assign credentials if required.
                '---------------------------------------------------------------
                If CBool(context.Application(Constant.COUPONSERVICESPROVIDER_REDEEMWEBSERVICE_AUTHENTICATIONREQUIRED)) Then
                    Dim netCredential As New NetworkCredential(context.Application(Constant.COUPONSERVICESPROVIDER_REDEEMWEBSERVICE_USER).ToString, _
                                                               context.Application(Constant.COUPONSERVICESPROVIDER_REDEEMWEBSERVICE_PASSWORD).ToString, _
                                                               Constant.COUPONSERVICESPROVIDER_DOMAIN)
                    Me.wsRedeemCouponService.Credentials = netCredential.GetCredential(uri, "Basic")
                    Me.wsRedeemCouponService.PreAuthenticate = True
                End If

            End If

            Return Me.wsRedeemCouponService

        End Get
    End Property

#End Region

    Public Sub New()
    End Sub

#Region "RedeemCoupon"

    ''' ------------------------------------------------------------------------
    ''' <summary>
    ''' 
    '''      Method:  RedeemCoupon
    ''' 
    ''' Description:  Creates a RedeemCoupon request and calls the Web
    '''               method.
    ''' 
    ''' </summary>
    ''' <param name="obj"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' ------------------------------------------------------------------------
    Public Overrides Function RedeemCoupon(ByVal obj As CharterDotCom.CommonEntities.Library.IProviderParameters) As CharterDotCom.CommonEntities.Library.IProviderResults

        Dim response As New CouponRedemptionResponse

        Try
            'Logger.ServiceLog("\ECommerceGateway.Providers\CouponProvider\ProviderManager\RedeemCoupon")

            If obj IsNot Nothing Then

                Dim request As CouponRedemptionRequest = CType(obj, CouponRedemptionRequest)

                '---------------------------------------------------------------
                ' Create request for Web service call.
                '---------------------------------------------------------------
                Dim serviceRequest As New WSRedemptionServiceRedeem.CouponRedemptionRequest

                With serviceRequest
                    .AccountId = request.AccountId
                    .CouponId = request.CouponId
                    .ChannelType = WSRedemptionServiceRedeem.ChannelType.CharterDotCom
                    .CSROverrideFlag = "N"
                End With

                '---------------------------------------------------------------
                ' Call Web service to redeem the coupon.
                '---------------------------------------------------------------
                Dim serviceResponse As WSRedemptionServiceRedeem.CouponRedemptionResponse
                serviceResponse = Me.RedemptionService.RedeemCoupon(serviceRequest)

                '---------------------------------------------------------------
                ' Validate response and assign return values.
                '---------------------------------------------------------------
                If Me.IsValid(serviceResponse, response) Then
                    With serviceResponse.CouponRedemptionResult

                        '-------------------------------------------------------
                        ' Assign coupon information to response.
                        '-------------------------------------------------------
                        response.CouponRedemptionResult = New CouponRedemptionResult
                        response.CouponRedemptionResult.AccountId = .AccountId
                        response.CouponRedemptionResult.AdjustmentAmount = .AdjustmentAmount
                        response.CouponRedemptionResult.ConfirmationNumber = .ConfirmationNumber
                        response.CouponRedemptionResult.CouponId = .CouponId
                        response.CouponRedemptionResult.CSRID = .CSRID
                        response.CouponRedemptionResult.CSRRole = .CSRRole
                        response.CouponRedemptionResult.CSRLocation = .CSRLocation
                        response.CouponRedemptionResult.CSRFirstName = .CSRFirstName
                        response.CouponRedemptionResult.CSRLastName = .CSRLastName
                        response.CouponRedemptionResult.RedemptionDate = .RedemptionDate
                        response.CouponRedemptionResult.RedemptionStatus = .RedemptionStatus
                        response.CouponRedemptionResult.CouponDescription = .CouponDescription
                        response.CouponRedemptionResult.ConfirmationMessage = .ConfirmationMessage
                        response.CouponRedemptionResult.ValidationFailureMessage = .ValidationFailureMessage

                        '-------------------------------------------------------
                        ' Assign redeemed event information to response.
                        '-------------------------------------------------------
                        If .RedeemedEvents IsNot Nothing Then
                            Dim eventList As New List(Of RedeemedEvent)
                            For Each serviceEvent As WSRedemptionServiceRedeem.RedeemedEvent In .RedeemedEvents
                                Dim newEvent As New RedeemedEvent
                                With serviceEvent
                                    newEvent.EventCode = .EventCode
                                    newEvent.EventTitle = .EventTitle
                                    newEvent.IsRedeemed = .IsRedeemed
                                End With
                                eventList.Add(newEvent)
                            Next
                            response.CouponRedemptionResult.RedeemedEvents = eventList.ToArray
                        End If

                    End With
                End If

            End If

        Catch ex As Exception
            response.Exception = True
            response.ExceptionMessage = ex.Message
            response.ExceptionStackTrace = ex.StackTrace
        End Try

        '-----------------------------------------------------------------------
        ' Return response.
        '-----------------------------------------------------------------------
        Return response

    End Function

    ''' ------------------------------------------------------------------------
    ''' <summary>
    ''' 
    '''      Method:  IsValid
    ''' 
    ''' Description:  Validates the response from a RedeemCoupon request.
    ''' 
    ''' </summary>
    ''' <param name="serviceResponse"></param>
    ''' <param name="response"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' ------------------------------------------------------------------------
    Private Function IsValid(ByVal serviceResponse As WSRedemptionServiceRedeem.CouponRedemptionResponse, ByRef response As CouponRedemptionResponse) As Boolean

        '-----------------------------------------------------------------------
        ' Check for missing response from Web service.
        '-----------------------------------------------------------------------
        If serviceResponse Is Nothing OrElse serviceResponse.Result Is Nothing Then
            Dim provider As New ErrorMappingProvider.ProviderManager
            response.Exception = True
            response.CharterDotCom_Friendly_Messages = provider.GetErrorMessageList("COUPONSERVICES", Constant.EXCEPTION_NODATA_RETURNED_CODE, Constant.EXCEPTION_NODATA_RETURNED)
            Return False
        End If

        '-----------------------------------------------------------------------
        ' Map Web service result object, regardless of errors.
        '-----------------------------------------------------------------------
        response.Result = Me.Map(serviceResponse.Result)

        '-----------------------------------------------------------------------
        ' Check for non-success result.
        '-----------------------------------------------------------------------
        If serviceResponse.Result.ReturnCode <> WSRedemptionServiceRedeem.ResultReturnCode.Success Then
            response.Exception = True
            With serviceResponse
                If .CouponRedemptionResult IsNot Nothing AndAlso Not String.IsNullOrEmpty(.CouponRedemptionResult.ValidationFailureMessage) Then
                    response.CharterDotCom_Friendly_Messages = .CouponRedemptionResult.ValidationFailureMessage
                ElseIf .Result.ReturnCode = WSRedemptionServiceRedeem.ResultReturnCode.NoDataFound Then
                    Dim provider As New ErrorMappingProvider.ProviderManager
                    response.CharterDotCom_Friendly_Messages = provider.GetErrorMessageList("COUPONSERVICES", Constant.EXCEPTION_NODATA_RETURNED_CODE, Constant.EXCEPTION_NODATA_RETURNED)
                End If
            End With
            Return False
        End If

        '-----------------------------------------------------------------------
        ' No errors found.
        '-----------------------------------------------------------------------
        response.Exception = False
        Return True

    End Function

#End Region

#Region "RedeemGiftCard"

    ''' ------------------------------------------------------------------------
    ''' <summary>
    ''' 
    '''      Method:  RedeemGiftCard
    ''' 
    ''' Description:  Creates a RedeemGiftCard request and calls the Web
    '''               method.
    ''' 
    ''' </summary>
    ''' <param name="obj"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' ------------------------------------------------------------------------
    Public Overrides Function RedeemGiftCard(ByVal obj As CharterDotCom.CommonEntities.Library.IProviderParameters) As CharterDotCom.CommonEntities.Library.IProviderResults

        Dim response As New GiftCardRedemptionResponse

        Try

            If obj IsNot Nothing Then

                Dim request As GiftCardRedemptionRequest = CType(obj, GiftCardRedemptionRequest)

                '---------------------------------------------------------------
                ' Create request for Web service call.
                '---------------------------------------------------------------
                Dim serviceRequest As New WSRedemptionServiceRedeem.GiftCardRedemptionRequest

                With serviceRequest
                    .AccountId = request.AccountId
                    .CouponId = request.CouponId
                    .ChannelType = WSRedemptionServiceRedeem.ChannelType.CharterDotCom
                    .CSROverrideFlag = "N"
                    If request.Address IsNot Nothing Then
                        .AddressLine1 = request.Address.Street1
                        .AddressLine2 = request.Address.Street2
                        .City = request.Address.City
                        .State = request.Address.State
                        .Zipcode = request.Address.Zip
                    End If
                End With

                '---------------------------------------------------------------
                ' Call Web service to redeem the gift card.
                '---------------------------------------------------------------
                Dim serviceResponse As WSRedemptionServiceRedeem.GiftCardRedemptionResponse
                serviceResponse = Me.RedemptionService.RedeemGiftCard(serviceRequest)

                '---------------------------------------------------------------
                ' Validate response and assign return values.
                '---------------------------------------------------------------
                If Me.IsValid(serviceResponse, response) Then
                    With serviceResponse.GiftcardRedemptionResult

                        '-------------------------------------------------------
                        ' Assign coupon information to response.
                        '-------------------------------------------------------
                        response.GiftCardRedemptionResult = New CouponRedemptionResult
                        response.GiftCardRedemptionResult.AccountId = .AccountId
                        response.GiftCardRedemptionResult.AdjustmentAmount = .AdjustmentAmount
                        response.GiftCardRedemptionResult.ConfirmationNumber = .ConfirmationNumber
                        response.GiftCardRedemptionResult.CouponId = .CouponId
                        response.GiftCardRedemptionResult.CSRID = .CSRID
                        response.GiftCardRedemptionResult.CSRRole = .CSRRole
                        response.GiftCardRedemptionResult.CSRLocation = .CSRLocation
                        response.GiftCardRedemptionResult.CSRFirstName = .CSRFirstName
                        response.GiftCardRedemptionResult.CSRLastName = .CSRLastName
                        response.GiftCardRedemptionResult.RedemptionDate = .RedemptionDate
                        response.GiftCardRedemptionResult.RedemptionStatus = .RedemptionStatus
                        response.GiftCardRedemptionResult.CouponDescription = .CouponDescription
                        response.GiftCardRedemptionResult.ConfirmationMessage = .ConfirmationMessage
                        response.GiftCardRedemptionResult.ValidationFailureMessage = .ValidationFailureMessage

                        '-------------------------------------------------------
                        ' Assign address information to response.
                        '-------------------------------------------------------
                        response.Address = New BLAddress
                        response.Address.Street1 = .Address1
                        response.Address.Street2 = .Address2
                        response.Address.City = .City
                        response.Address.State = .State
                        response.Address.Zip = .Zipcode

                        '-------------------------------------------------------
                        ' Assign redeemed event information to response.
                        '-------------------------------------------------------
                        If .RedeemedEvents IsNot Nothing Then
                            Dim eventList As New List(Of RedeemedEvent)
                            For Each serviceEvent As WSRedemptionServiceRedeem.RedeemedEvent In .RedeemedEvents
                                Dim newEvent As New RedeemedEvent
                                With serviceEvent
                                    newEvent.EventCode = .EventCode
                                    newEvent.EventTitle = .EventTitle
                                    newEvent.IsRedeemed = .IsRedeemed
                                End With
                                eventList.Add(newEvent)
                            Next
                            response.GiftCardRedemptionResult.RedeemedEvents = eventList.ToArray
                        End If

                    End With
                End If

            End If

        Catch ex As Exception
            response.Exception = True
            response.ExceptionMessage = ex.Message
            response.ExceptionStackTrace = ex.StackTrace
        End Try

        '-----------------------------------------------------------------------
        ' Return response.
        '-----------------------------------------------------------------------
        Return response

    End Function

    ''' ------------------------------------------------------------------------
    ''' <summary>
    ''' 
    '''      Method:  IsValid
    ''' 
    ''' Description:  Validates the response from a RedeemGiftCard request.
    ''' 
    ''' </summary>
    ''' <param name="serviceResponse"></param>
    ''' <param name="response"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' ------------------------------------------------------------------------
    Private Function IsValid(ByVal serviceResponse As WSRedemptionServiceRedeem.GiftCardRedemptionResponse, ByRef response As GiftCardRedemptionResponse) As Boolean

        '-----------------------------------------------------------------------
        ' Check for missing response from Web service.
        '-----------------------------------------------------------------------
        If serviceResponse Is Nothing OrElse serviceResponse.Result Is Nothing Then
            Dim provider As New ErrorMappingProvider.ProviderManager
            response.Exception = True
            response.CharterDotCom_Friendly_Messages = provider.GetErrorMessageList("COUPONSERVICES", Constant.EXCEPTION_NODATA_RETURNED_CODE, Constant.EXCEPTION_NODATA_RETURNED)
            Return False
        End If

        '-----------------------------------------------------------------------
        ' Map Web service result object, regardless of errors.
        '-----------------------------------------------------------------------
        response.Result = Me.Map(serviceResponse.Result)

        '-----------------------------------------------------------------------
        ' Check for non-success result.
        '-----------------------------------------------------------------------
        If serviceResponse.Result.ReturnCode <> WSRedemptionServiceRedeem.ResultReturnCode.Success Then
            response.Exception = True
            With serviceResponse
                If .GiftcardRedemptionResult IsNot Nothing AndAlso Not String.IsNullOrEmpty(.GiftcardRedemptionResult.ValidationFailureMessage) Then
                    response.CharterDotCom_Friendly_Messages = .GiftcardRedemptionResult.ValidationFailureMessage
                ElseIf .Result.ReturnCode = WSRedemptionServiceRedeem.ResultReturnCode.NoDataFound Then
                    Dim provider As New ErrorMappingProvider.ProviderManager
                    response.CharterDotCom_Friendly_Messages = provider.GetErrorMessageList("COUPONSERVICES", Constant.EXCEPTION_NODATA_RETURNED_CODE, Constant.EXCEPTION_NODATA_RETURNED)
                End If
            End With
            Return False
        End If

        '-----------------------------------------------------------------------
        ' No errors found.
        '-----------------------------------------------------------------------
        response.Exception = False
        Return True

    End Function

#End Region

#Region "GetCouponStatus"
    Public Overrides Function GetCouponStatus(ByVal obj As CharterDotCom.CommonEntities.Library.IProviderParameters) As CharterDotCom.CommonEntities.Library.IProviderResults
        '#######################################
        'TEMP LOCAL VARIABLES FOR REQUEST OBJECT
        '#######################################
        Dim objTempRequest As GetCouponStatusRequest
        Dim objRequest As New WSRedemptionServiceStatus.CouponStatusRequest

        '#######################################
        'TEMP LOCAL VARIABLES FOR RESPONSE OBJECT
        '#######################################
        Dim objTempResponse As New WSRedemptionServiceStatus.CouponStatusResponse
        Dim objResponse As New GetCouponStatusResponse

        Try
            If Not (obj Is Nothing) Then
                objTempRequest = CType(obj, GetCouponStatusRequest)
                If Not (objTempRequest.accountId Is Nothing) Then
                    objRequest.AccountId = objTempRequest.accountId
                End If
                If Not (objTempRequest.couponID Is Nothing) Then
                    objRequest.CouponId = objTempRequest.couponID
                End If
                objRequest.ChannelType = WSRedemptionServiceStatus.ChannelType.CharterDotCom
                ''#####################################
                ''EXECUTE THE COUPON STATUS WEB SERVICE
                ''#####################################
                'Configure settings for Coupon Status WebService
                Dim context As HttpContext = HttpContext.Current
                Dim netCredential As NetworkCredential
                Dim uri As Uri
                uri = New Uri(context.Application(Constant.COUPONSERVICESPROVIDER_COUPONSTATUSWEBSERVICE_URL))
                wsCouponStatusService = New WSRedemptionServiceStatus.CouponStatusService
                Me.wsCouponStatusService.Url = uri.AbsoluteUri
                If CBool(context.Application(Constant.COUPONSERVICESPROVIDER_COUPONSTATUSWEBSERVICE_AUTHENTICATIONREQUIRED)) Then
                    netCredential = New NetworkCredential(context.Application(Constant.COUPONSERVICESPROVIDER_COUPONSTATUSWEBSERVICE_USER).ToString, _
                                                          context.Application(Constant.COUPONSERVICESPROVIDER_COUPONSTATUSWEBSERVICE_PASSWORD).ToString, _
                                                          Constant.COUPONSERVICESPROVIDER_DOMAIN)
                    wsCouponStatusService.Credentials = netCredential.GetCredential(uri, "Basic")
                    wsCouponStatusService.PreAuthenticate = True
                End If
                'netCredential = New NetworkCredential("tst_CouponMgmt", "T$t_C0up0n!", "Chtr")

                'wsCouponStatusService.Credentials = netCredential.GetCredential(uri, "Basic")

                'wsCouponStatusService.PreAuthenticate = True


                'Call Webservice Method
                objTempResponse = wsCouponStatusService.GetCouponStatus(objRequest)
                'Check for errors
                If (objTempResponse Is Nothing) Then
                    Dim lErrorMappingProvider As New ErrorMappingProvider.ProviderManager
                    objResponse.CharterDotCom_Friendly_Messages = lErrorMappingProvider.GetErrorMessageList("COUPONSERVICES", Constant.EXCEPTION_NODATA_RETURNED_CODE, Constant.EXCEPTION_NODATA_RETURNED)
                    'Throw New Exception(Constant.EXCEPTION_NODATA_RETURNED)
                End If
                If (objTempResponse.Result Is Nothing) Then
                    Dim lErrorMappingProvider As New ErrorMappingProvider.ProviderManager
                    objResponse.CharterDotCom_Friendly_Messages = lErrorMappingProvider.GetErrorMessageList("COUPONSERVICES", Constant.EXCEPTION_NODATA_RETURNED_CODE, Constant.EXCEPTION_NODATA_RETURNED)
                    'Throw New Exception(Constant.EXCEPTION_NODATA_RETURNED)
                End If
                If Not (objTempResponse.Result.ReturnCode = CouponProvider.WSRedemptionServiceStatus.ResultReturnCode.Success Or objTempResponse.Result.ReturnCode = CouponProvider.WSRedemptionServiceStatus.ResultReturnCode.BusinessRuleNotMet Or objTempResponse.Result.ReturnCode = CouponProvider.WSRedemptionServiceStatus.ResultReturnCode.NoDataFound) Then
                    Dim lErrorMappingProvider As New ErrorMappingProvider.ProviderManager
                    objResponse.CharterDotCom_Friendly_Messages = lErrorMappingProvider.GetErrorMessageList("COUPONSERVICES", objTempResponse.Result.ReturnCode.ToString(), objTempResponse.Result.ReturnCode.ToString())
                    'Throw New Exception(objTempResponse.Result.ReturnCode.ToString())
                End If
                '#########################################################################################
                'translate back to a common object in the gateway, visible from Provider and the BL both.
                '#########################################################################################

                '##########Coupon Status Object##########
                If Not (objTempResponse.CouponStatusResult Is Nothing) Then
                    objResponse.CouponStatusResult = New CouponStatusResult
                    'objResponse.CouponStatusResult.AccountId = objTempResponse.CouponStatusResult.AccountId
                    objResponse.CouponStatusResult.AccountId = objTempResponse.CouponStatusResult.RedeemedAccountId
                    objResponse.CouponStatusResult.CouponId = objTempResponse.CouponStatusResult.CouponId
                    objResponse.CouponStatusResult.CouponDescription = objTempResponse.CouponStatusResult.CouponDescription
                    objResponse.CouponStatusResult.CouponOffer = objTempResponse.CouponStatusResult.CouponOffer
                    Select Case objTempResponse.CouponStatusResult.CouponStatus
                        Case WSRedemptionServiceStatus.CouponStatus.Redeemed
                            objResponse.CouponStatusResult.CouponStatus = CouponStatus.Redeemed
                        Case WSRedemptionServiceStatus.CouponStatus.Active
                            objResponse.CouponStatusResult.CouponStatus = CouponStatus.Active
                        Case WSRedemptionServiceStatus.CouponStatus.InActive
                            objResponse.CouponStatusResult.CouponStatus = CouponStatus.InActive
                        Case WSRedemptionServiceStatus.CouponStatus.Expired
                            objResponse.CouponStatusResult.CouponStatus = CouponStatus.Expired
                        Case Else
                            objResponse.CouponStatusResult.CouponStatus = objTempResponse.CouponStatusResult.CouponStatus
                    End Select
                    objResponse.CouponStatusResult.CouponStatus = objTempResponse.CouponStatusResult.CouponStatus
                    objResponse.CouponStatusResult.CouponStartDate = objTempResponse.CouponStatusResult.CouponStartDate
                    objResponse.CouponStatusResult.CouponEndDate = objTempResponse.CouponStatusResult.CouponEndDate
                    objResponse.CouponStatusResult.ActivationStartDate = objTempResponse.CouponStatusResult.ActivationStartDate
                    objResponse.CouponStatusResult.ActivationEndDate = objTempResponse.CouponStatusResult.ActivationEndDate
                    objResponse.CouponStatusResult.AllowedRedemptions = objTempResponse.CouponStatusResult.AllowedRedemptions
                    objResponse.CouponStatusResult.NumberOfOrderedEvents = objTempResponse.CouponStatusResult.AllowedRedemptions
                    objResponse.CouponStatusResult.ExclusionType = objTempResponse.CouponStatusResult.ExclusionType
                    objResponse.CouponStatusResult.RedemptionDate = objTempResponse.CouponStatusResult.RedemptionDate
                    objResponse.CouponStatusResult.RedemptionChannel = objTempResponse.CouponStatusResult.RedemptionChannel
                    objResponse.CouponStatusResult.ConfirmationNumber = objTempResponse.CouponStatusResult.ConfirmationNumber
                    objResponse.CouponStatusResult.CSRLocation = objTempResponse.CouponStatusResult.CSRLocation
                    objResponse.CouponStatusResult.CSRRole = objTempResponse.CouponStatusResult.CSRRole
                    objResponse.CouponStatusResult.CSRFirstName = objTempResponse.CouponStatusResult.CSRFirstName
                    objResponse.CouponStatusResult.CSRLastName = objTempResponse.CouponStatusResult.CSRLastName

                    '############Redeemed Event Object##############
                    If Not (objTempResponse.CouponStatusResult.RedeemedEvents Is Nothing) Then
                        ReDim objResponse.CouponStatusResult.RedeemedEvents(objTempResponse.CouponStatusResult.RedeemedEvents.GetUpperBound(0))
                        For iRedeemedEvent As Integer = 0 To objTempResponse.CouponStatusResult.RedeemedEvents.GetUpperBound(0)
                            objResponse.CouponStatusResult.RedeemedEvents(iRedeemedEvent) = New RedeemedEventCouponStatus
                            objResponse.CouponStatusResult.RedeemedEvents(iRedeemedEvent).EventCode = objTempResponse.CouponStatusResult.RedeemedEvents(iRedeemedEvent).EventCode
                            objResponse.CouponStatusResult.RedeemedEvents(iRedeemedEvent).EventTitle = objTempResponse.CouponStatusResult.RedeemedEvents(iRedeemedEvent).EventTitle
                            objResponse.CouponStatusResult.RedeemedEvents(iRedeemedEvent).IsRedeemed = objTempResponse.CouponStatusResult.RedeemedEvents(iRedeemedEvent).IsRedeemed
                        Next
                    End If
                    '############Business Rule Object##############
                    If Not (objTempResponse.CouponStatusResult.BusinessRule Is Nothing) Then
                        ReDim objResponse.CouponStatusResult.BusinessRule(objTempResponse.CouponStatusResult.BusinessRule.GetUpperBound(0))
                        For iBusinessRule As Integer = 0 To objTempResponse.CouponStatusResult.BusinessRule.GetUpperBound(0)
                            objResponse.CouponStatusResult.BusinessRule(iBusinessRule) = New BusinessRuleCouponStatus
                            objResponse.CouponStatusResult.BusinessRule(iBusinessRule).RuleID = objTempResponse.CouponStatusResult.BusinessRule(iBusinessRule).RuleID
                            objResponse.CouponStatusResult.BusinessRule(iBusinessRule).RuleDescription = objTempResponse.CouponStatusResult.BusinessRule(iBusinessRule).RuleDescription
                        Next
                    End If
                    '############Redemption Attempt Object##############
                    If Not (objTempResponse.CouponStatusResult.RedemptionAttempts Is Nothing) Then
                        ReDim objResponse.CouponStatusResult.RedemptionAttempts(objTempResponse.CouponStatusResult.RedemptionAttempts.GetUpperBound(0))
                        For iRedemptionAttempt As Integer = 0 To objTempResponse.CouponStatusResult.RedemptionAttempts.GetUpperBound(0)
                            objResponse.CouponStatusResult.RedemptionAttempts(iRedemptionAttempt) = New RedemptionAttemptCouponStatus
                            objResponse.CouponStatusResult.RedemptionAttempts(iRedemptionAttempt).Channel = objTempResponse.CouponStatusResult.RedemptionAttempts(iRedemptionAttempt).Channel
                            objResponse.CouponStatusResult.RedemptionAttempts(iRedemptionAttempt).InvalidMessage = objTempResponse.CouponStatusResult.RedemptionAttempts(iRedemptionAttempt).InvalidMessage
                        Next
                    End If
                End If

                '############Result Object##############
                If Not (objTempResponse.Result Is Nothing) Then
                    objResponse.Result = New ResultCoupon
                    objResponse.Result.DateTime = objTempResponse.Result.DateTime
                    objResponse.Result.Description = objTempResponse.Result.Description

                    If Not (objTempResponse.Result.ExceptionInfo Is Nothing) Then
                        objResponse.Result.ExceptionInfo = New ResultExceptionInfoCoupon
                        objResponse.Result.ExceptionInfo.Code = objTempResponse.Result.ExceptionInfo.Code
                        objResponse.Result.ExceptionInfo.Message = objTempResponse.Result.ExceptionInfo.Message
                        objResponse.Result.ExceptionInfo.StackTrace = objTempResponse.Result.ExceptionInfo.StackTrace
                        objResponse.Result.ExceptionInfo.Type = objTempResponse.Result.ExceptionInfo.Type
                    End If

                    objResponse.Result.ReferenceCode = objTempResponse.Result.ReferenceCode
                    objResponse.Result.ReturnCode = objTempResponse.Result.ReturnCode
                    objResponse.Result.Server = objTempResponse.Result.Server
                    objResponse.Result.Source = objTempResponse.Result.Source

                    If Not (objTempResponse.Result.StatusMessages Is Nothing) Then
                        For i2 As Integer = 0 To objTempResponse.Result.StatusMessages.GetUpperBound(0)
                            objResponse.Result.StatusMessages(i2) = New CsgStatusMessageCoupon
                            objResponse.Result.StatusMessages(i2).Code = objTempResponse.Result.StatusMessages(i2).Code
                            objResponse.Result.StatusMessages(i2).Message = objTempResponse.Result.StatusMessages(i2).Message
                        Next
                    End If
                    objResponse.Result.Type = objTempResponse.Result.Type
                End If
            End If
            Return objResponse
        Catch ex As Exception
            objResponse.Exception = True
            objResponse.ExceptionMessage = ex.Message
            objResponse.ExceptionStackTrace = ex.StackTrace
            Return objResponse
        Finally

        End Try
    End Function
#End Region

#Region "GetCustomerAddress"

    ''' ------------------------------------------------------------------------
    ''' <summary>
    ''' 
    '''      Method:  GetCustomerAddress
    ''' 
    ''' Description:  Creates a GetCustomerAddress request and calls the Web
    '''               method.
    ''' 
    ''' </summary>
    ''' <param name="obj"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' ------------------------------------------------------------------------
    Public Overrides Function GetCustomerAddress(ByVal obj As CharterDotCom.CommonEntities.Library.IProviderParameters) As CharterDotCom.CommonEntities.Library.IProviderResults

        Dim response As New GetCustomerAddressResponse

        Try

            If obj IsNot Nothing Then

                Dim request As GetCustomerAddressRequest = CType(obj, GetCustomerAddressRequest)

                '---------------------------------------------------------------
                ' Create request for Web service call.
                '---------------------------------------------------------------
                Dim serviceRequest As New WSRedemptionServiceRedeem.CustomerAddressRequest

                With serviceRequest
                    .AccountNumber = request.AccountId
                End With

                '---------------------------------------------------------------
                ' Call Web service to retrieve account addresses.
                '---------------------------------------------------------------
                Dim serviceResponse As WSRedemptionServiceRedeem.CustomerAddressResponse
                serviceResponse = Me.RedemptionService.GetCustomerAddress(serviceRequest)

                '---------------------------------------------------------------
                ' Validate response and assign return values.
                '---------------------------------------------------------------
                If Me.IsValid(serviceResponse, response) Then
                    With serviceResponse.CustomerAddressResult.CustomerAddresses

                        response.AccountId = .AccountNumber

                        If Not String.IsNullOrEmpty(.ServiceAddressLine1) AndAlso _
                           Not String.IsNullOrEmpty(.ServiceCity) AndAlso _
                           Not String.IsNullOrEmpty(.ServiceState) AndAlso _
                           Not String.IsNullOrEmpty(.ServiceZip) Then
                            response.ServiceAddress = New BLAddress
                            response.ServiceAddress.Street1 = .ServiceAddressLine1
                            response.ServiceAddress.Street2 = .ServiceAddressLine2
                            response.ServiceAddress.City = .ServiceCity
                            response.ServiceAddress.State = .ServiceState
                            response.ServiceAddress.Zip = .ServiceZip
                        End If

                        If Not String.IsNullOrEmpty(.BillingAddressLine1) AndAlso _
                           Not String.IsNullOrEmpty(.BillingCity) AndAlso _
                           Not String.IsNullOrEmpty(.BillingState) AndAlso _
                           Not String.IsNullOrEmpty(.BillingZip) Then
                            response.BillingAddress = New BLAddress
                            response.BillingAddress.Street1 = .BillingAddressLine1
                            response.BillingAddress.Street2 = .BillingAddressLine2
                            response.BillingAddress.City = .BillingCity
                            response.BillingAddress.State = .BillingState
                            response.BillingAddress.Zip = .BillingZip
                        End If

                    End With
                End If

            End If

        Catch ex As Exception
            response.Exception = True
            response.ExceptionMessage = ex.Message
            response.ExceptionStackTrace = ex.StackTrace
        End Try

        '-----------------------------------------------------------------------
        ' Return response.
        '-----------------------------------------------------------------------
        Return response

    End Function

    ''' ------------------------------------------------------------------------
    ''' <summary>
    ''' 
    '''      Method:  IsValid
    ''' 
    ''' Description:  Validates the response from a GetCustomerAddress request.
    ''' 
    ''' </summary>
    ''' <param name="serviceResponse"></param>
    ''' <param name="response"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' ------------------------------------------------------------------------
    Private Function IsValid(ByVal serviceResponse As WSRedemptionServiceRedeem.CustomerAddressResponse, ByRef response As GetCustomerAddressResponse) As Boolean

        '-----------------------------------------------------------------------
        ' Check for missing response from Web service.
        '-----------------------------------------------------------------------
        If serviceResponse Is Nothing OrElse _
           serviceResponse.Result Is Nothing Then
            Dim provider As New ErrorMappingProvider.ProviderManager
            response.Exception = True
            response.CharterDotCom_Friendly_Messages = provider.GetErrorMessageList("COUPONSERVICES", Constant.EXCEPTION_NODATA_RETURNED_CODE, Constant.EXCEPTION_NODATA_RETURNED)
            Return False
        End If

        '-----------------------------------------------------------------------
        ' Map Web service result object, regardless of errors.
        '-----------------------------------------------------------------------
        response.Result = Me.Map(serviceResponse.Result)

        '-----------------------------------------------------------------------
        ' Check for non-success result.
        '-----------------------------------------------------------------------
        If serviceResponse.Result.ReturnCode <> WSRedemptionServiceRedeem.ResultReturnCode.Success OrElse _
           serviceResponse.CustomerAddressResult Is Nothing OrElse _
           serviceResponse.CustomerAddressResult.CustomerAddresses Is Nothing Then
            response.Exception = True
            Return False
        End If

        '-----------------------------------------------------------------------
        ' No errors found.
        '-----------------------------------------------------------------------
        response.Exception = False
        Return True

    End Function

#End Region

#Region "GetCustomerRedemptionHistory"
    Public Overrides Function GetCustomerRedemptionHistory(ByVal obj As CharterDotCom.CommonEntities.Library.IProviderParameters) As CharterDotCom.CommonEntities.Library.IProviderResults
        '#######################################
        'TEMP LOCAL VARIABLES FOR REQUEST OBJECT
        '#######################################
        Dim objTempRequest As GetCustomerRedemptionHistoryRequest
        Dim objRequest As New WSRedemptionServiceHistory.CouponRedemptionHistoryRequest

        '#######################################
        'TEMP LOCAL VARIABLES FOR RESPONSE OBJECT
        '#######################################
        Dim objTempResponse As New WSRedemptionServiceHistory.CouponRedemptionHistoryResponse
        Dim objResponse As New GetCustomerRedemptionHistoryResponse

        Try
            If Not (obj Is Nothing) Then
                objTempRequest = CType(obj, GetCustomerRedemptionHistoryRequest)
                If Not (objTempRequest.accountId Is Nothing) Then
                    objRequest.AccountId = objTempRequest.accountId
                End If
                'objRequest.ChannelType = ChannelType.CharterDotCom
                objRequest.ChannelType = WSRedemptionServiceHistory.ChannelType.CharterDotCom
                ''#######################################################
                ''EXECUTE THE GET CUSTOMER REDEMPTION HISTORY WEB SERVICE
                ''#######################################################
                'Configure settings for Customer Redemption History WebService
                Dim context As HttpContext = HttpContext.Current
                Dim netCredential As NetworkCredential
                Dim uri As Uri
                uri = New Uri(context.Application(Constant.COUPONSERVICESPROVIDER_CUSTOMERREDEMPTIONHISTORYWEBSERVICE_URL))
                wsCustomerRedemptionHistoryService = New WSRedemptionServiceHistory.RedemotionHistoryService
                Me.wsCustomerRedemptionHistoryService.Url = uri.AbsoluteUri
                If CBool(context.Application(Constant.COUPONSERVICESPROVIDER_CUSTOMERREDEMPTIONHISTORYWEBSERVICE_AUTHENTICATIONREQUIRED)) Then
                    netCredential = New NetworkCredential(context.Application(Constant.COUPONSERVICESPROVIDER_CUSTOMERREDEMPTIONHISTORYWEBSERVICE_USER).ToString, _
                                                          context.Application(Constant.COUPONSERVICESPROVIDER_CUSTOMERREDEMPTIONHISTORYWEBSERVICE_PASSWORD).ToString, _
                                                          Constant.COUPONSERVICESPROVIDER_DOMAIN)
                    wsCustomerRedemptionHistoryService.Credentials = netCredential.GetCredential(uri, "Basic")
                    wsCustomerRedemptionHistoryService.PreAuthenticate = True
                End If
                'netCredential = New NetworkCredential("tst_CouponMgmt", "T$t_C0up0n!", "Chtr")

                'wsCustomerRedemptionHistoryService.Credentials = netCredential.GetCredential(uri, "Basic")

                'wsCustomerRedemptionHistoryService.PreAuthenticate = True

                'Call Customer Redemption History Webservice Method
                objTempResponse = wsCustomerRedemptionHistoryService.GetCouponRemptionHistory(objRequest)
                'Check for errors
                If (objTempResponse Is Nothing) Then
                    Dim lErrorMappingProvider As New ErrorMappingProvider.ProviderManager
                    objResponse.CharterDotCom_Friendly_Messages = lErrorMappingProvider.GetErrorMessageList("COUPONSERVICES", Constant.EXCEPTION_NODATA_RETURNED_CODE, Constant.EXCEPTION_NODATA_RETURNED)
                    'Throw New Exception(Constant.EXCEPTION_NODATA_RETURNED)
                End If
                If (objTempResponse.Result Is Nothing) Then
                    Dim lErrorMappingProvider As New ErrorMappingProvider.ProviderManager
                    objResponse.CharterDotCom_Friendly_Messages = lErrorMappingProvider.GetErrorMessageList("COUPONSERVICES", Constant.EXCEPTION_NODATA_RETURNED_CODE, Constant.EXCEPTION_NODATA_RETURNED)
                    'Throw New Exception(Constant.EXCEPTION_NODATA_RETURNED)
                End If
                If Not (objTempResponse.Result.ReturnCode = CouponProvider.WSRedemptionServiceHistory.ResultReturnCode.Success Or objTempResponse.Result.ReturnCode = CouponProvider.WSRedemptionServiceHistory.ResultReturnCode.NoDataFound Or objTempResponse.Result.ReturnCode = CouponProvider.WSRedemptionServiceHistory.ResultReturnCode.BusinessRuleNotMet) Then
                    Dim lErrorMappingProvider As New ErrorMappingProvider.ProviderManager
                    objResponse.CharterDotCom_Friendly_Messages = lErrorMappingProvider.GetErrorMessageList("COUPONSERVICES", objTempResponse.Result.ReturnCode.ToString(), objTempResponse.Result.ReturnCode.ToString())
                    'Throw New Exception(objTempResponse.Result.ReturnCode.ToString())
                End If
                '#########################################################################################
                'translate back to a common object in the gateway, visible from Provider and the BL both.
                '#########################################################################################

                '##############Redemption History Object################
                If Not (objTempResponse.CouponRedemptionHistoryResult Is Nothing) Then
                    ReDim objResponse.CouponRedemptionHistoryResult(objTempResponse.CouponRedemptionHistoryResult.GetUpperBound(0))
                    For iHistoryResult As Integer = 0 To objTempResponse.CouponRedemptionHistoryResult.GetUpperBound(0)
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult) = New CustomerRedemptionHistoryResult
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).AccountId = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedeemedAccountId
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).CouponId = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).CouponId
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).CouponDescription = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).CouponDescription
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).CouponOffer = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).CouponOffer
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).CouponStatus = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).CouponStatus
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).CouponStartDate = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).CouponStartDate
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).CouponEndDate = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).CouponEndDate
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).ActivationStartDate = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).ActivationStartDate
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).ActivationEndDate = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).ActivationEndDate
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).AllowedRedemptions = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).AllowedRedemptions
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).NumberOfOrderedEvents = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).AllowedRedemptions
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).ExclusionType = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).ExclusionType
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).RedemptionDate = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedemptionDate
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).RedemptionChannel = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedemptionChannel
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).ConfirmationNumber = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).ConfirmationNumber
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).CSRLocation = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).CSRLocation
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).CSRRole = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).CSRRole
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).CSRFirstName = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).CSRFirstName
                        objResponse.CouponRedemptionHistoryResult(iHistoryResult).CSRLastName = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).CSRLastName
                        '##############Redeeemed Event Object################
                        If Not (objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedeemedEvents Is Nothing) Then
                            ReDim objResponse.CouponRedemptionHistoryResult(iHistoryResult).RedeemedEvents(objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedeemedEvents.GetUpperBound(0))
                            For iRedeemedEvent As Integer = 0 To objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedeemedEvents.GetUpperBound(0)
                                objResponse.CouponRedemptionHistoryResult(iHistoryResult).RedeemedEvents(iRedeemedEvent) = New RedeemedEventCustomerRedemptionHistory
                                objResponse.CouponRedemptionHistoryResult(iHistoryResult).RedeemedEvents(iRedeemedEvent).EventCode = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedeemedEvents(iRedeemedEvent).EventCode
                                objResponse.CouponRedemptionHistoryResult(iHistoryResult).RedeemedEvents(iRedeemedEvent).EventTitle = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedeemedEvents(iRedeemedEvent).EventTitle
                                objResponse.CouponRedemptionHistoryResult(iHistoryResult).RedeemedEvents(iRedeemedEvent).IsRedeemed = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedeemedEvents(iRedeemedEvent).IsRedeemed
                            Next
                        End If
                        '##############Business Rule Object################
                        If Not (objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).BusinessRule Is Nothing) Then
                            ReDim objResponse.CouponRedemptionHistoryResult(iHistoryResult).BusinessRule(objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).BusinessRule.GetUpperBound(0))
                            For iBusinessRule As Integer = 0 To objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).BusinessRule.GetUpperBound(0)
                                objResponse.CouponRedemptionHistoryResult(iHistoryResult).BusinessRule(iBusinessRule) = New BusinessRuleCustomerRedemptionHistory
                                objResponse.CouponRedemptionHistoryResult(iHistoryResult).BusinessRule(iBusinessRule).RuleID = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).BusinessRule(iBusinessRule).RuleID
                                objResponse.CouponRedemptionHistoryResult(iHistoryResult).BusinessRule(iBusinessRule).RuleDescription = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).BusinessRule(iBusinessRule).RuleDescription
                            Next
                        End If
                        '##############Redemption Attempts Object################
                        If Not (objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedemptionAttempts Is Nothing) Then
                            ReDim objResponse.CouponRedemptionHistoryResult(iHistoryResult).RedemptionAttempts(objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedemptionAttempts.GetUpperBound(0))
                            For iRedemptionAttempt As Integer = 0 To objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedemptionAttempts.GetUpperBound(0)
                                objResponse.CouponRedemptionHistoryResult(iHistoryResult).RedemptionAttempts(iRedemptionAttempt) = New RedemptionAttemptCustomerRedemptionHistory
                                objResponse.CouponRedemptionHistoryResult(iHistoryResult).RedemptionAttempts(iRedemptionAttempt).Channel = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedemptionAttempts(iRedemptionAttempt).Channel
                                objResponse.CouponRedemptionHistoryResult(iHistoryResult).RedemptionAttempts(iRedemptionAttempt).InvalidMessage = objTempResponse.CouponRedemptionHistoryResult(iHistoryResult).RedemptionAttempts(iRedemptionAttempt).InvalidMessage
                            Next
                        End If
                    Next
                End If
                '##############Result Object################
                If Not (objTempResponse.Result Is Nothing) Then
                    objResponse.Result = New ResultCoupon
                    objResponse.Result.DateTime = objTempResponse.Result.DateTime
                    objResponse.Result.Description = objTempResponse.Result.Description

                    If Not (objTempResponse.Result.ExceptionInfo Is Nothing) Then
                        objResponse.Result.ExceptionInfo = New ResultExceptionInfoCoupon
                        objResponse.Result.ExceptionInfo.Code = objTempResponse.Result.ExceptionInfo.Code
                        objResponse.Result.ExceptionInfo.Message = objTempResponse.Result.ExceptionInfo.Message
                        objResponse.Result.ExceptionInfo.StackTrace = objTempResponse.Result.ExceptionInfo.StackTrace
                        objResponse.Result.ExceptionInfo.Type = objTempResponse.Result.ExceptionInfo.Type
                    End If

                    objResponse.Result.ReferenceCode = objTempResponse.Result.ReferenceCode
                    objResponse.Result.ReturnCode = objTempResponse.Result.ReturnCode
                    objResponse.Result.Server = objTempResponse.Result.Server
                    objResponse.Result.Source = objTempResponse.Result.Source

                    If Not (objTempResponse.Result.StatusMessages Is Nothing) Then
                        For i2 As Integer = 0 To objTempResponse.Result.StatusMessages.GetUpperBound(0)
                            objResponse.Result.StatusMessages(i2) = New CsgStatusMessageCoupon
                            objResponse.Result.StatusMessages(i2).Code = objTempResponse.Result.StatusMessages(i2).Code
                            objResponse.Result.StatusMessages(i2).Message = objTempResponse.Result.StatusMessages(i2).Message
                        Next
                    End If

                    objResponse.Result.Type = objTempResponse.Result.Type
                End If
            End If
            Return objResponse
        Catch ex As Exception
            objResponse.Exception = True
            objResponse.ExceptionMessage = ex.Message
            objResponse.ExceptionStackTrace = ex.StackTrace
            Return objResponse

        Finally

        End Try

    End Function
#End Region

#Region "GiftCardLookup"

    ''' ------------------------------------------------------------------------
    ''' <summary>
    ''' 
    '''      Method:  GiftCardLookup
    ''' 
    ''' Description:  Creates a GiftCardLookup request and calls the Web
    '''               method.
    ''' 
    ''' </summary>
    ''' <param name="obj"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' ------------------------------------------------------------------------
    Public Overrides Function GiftCardLookup(ByVal obj As CharterDotCom.CommonEntities.Library.IProviderParameters) As CharterDotCom.CommonEntities.Library.IProviderResults

        Dim response As New GiftCardLookupResponse

        Try

            If obj IsNot Nothing Then

                Dim request As GiftCardLookupRequest = CType(obj, GiftCardLookupRequest)

                '---------------------------------------------------------------
                ' Create request for Web service call.
                '---------------------------------------------------------------
                Dim serviceRequest As New WSRedemptionServiceRedeem.CouponRedemptionRequest

                With serviceRequest
                    .AccountId = request.AccountId
                    .CouponId = request.CouponId
                    .ChannelType = WSRedemptionServiceRedeem.ChannelType.CharterDotCom
                    .CSROverrideFlag = "N"
                End With

                '---------------------------------------------------------------
                ' Call Web service to determine type of coupon.
                '---------------------------------------------------------------
                Dim serviceResponse As WSRedemptionServiceRedeem.GiftCardLookupResponse
                serviceResponse = Me.RedemptionService.GiftCardLookup(serviceRequest)

                '---------------------------------------------------------------
                ' Validate response and assign return values.
                '---------------------------------------------------------------
                If Me.IsValid(serviceResponse, response) Then
                    With serviceResponse.GiftcardLookupResult
                        response.AccountId = .AccountId
                        response.CouponId = .CouponId
                        response.CouponType = .CouponOrGiftCard
                    End With
                End If

            End If

        Catch ex As Exception
            response.Exception = True
            response.ExceptionMessage = ex.Message
            response.ExceptionStackTrace = ex.StackTrace
        End Try

        '-----------------------------------------------------------------------
        ' Return response.
        '-----------------------------------------------------------------------
        Return response

    End Function

    ''' ------------------------------------------------------------------------
    ''' <summary>
    ''' 
    '''      Method:  IsValid
    ''' 
    ''' Description:  Validates the response from a GiftCardLookup request.
    ''' 
    ''' </summary>
    ''' <param name="serviceResponse"></param>
    ''' <param name="response"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' ------------------------------------------------------------------------
    Private Function IsValid(ByVal serviceResponse As WSRedemptionServiceRedeem.GiftCardLookupResponse, ByRef response As GiftCardLookupResponse) As Boolean

        '-----------------------------------------------------------------------
        ' Check for missing response from Web service.
        '-----------------------------------------------------------------------
        If serviceResponse Is Nothing OrElse _
           serviceResponse.Result Is Nothing OrElse _
           serviceResponse.Result.ReturnCode = WSRedemptionServiceRedeem.ResultReturnCode.NoDataFound Then
            Dim provider As New ErrorMappingProvider.ProviderManager
            response.Exception = True
            response.CharterDotCom_Friendly_Messages = provider.GetErrorMessageList("COUPONSERVICES", Constant.EXCEPTION_NODATA_RETURNED_CODE, Constant.EXCEPTION_NODATA_RETURNED)
            Return False
        End If

        '-----------------------------------------------------------------------
        ' Map Web service result object, regardless of errors.
        '-----------------------------------------------------------------------
        response.Result = Me.Map(serviceResponse.Result)

        '-----------------------------------------------------------------------
        ' Check for non-success result.
        '-----------------------------------------------------------------------
        If serviceResponse.Result.ReturnCode <> WSRedemptionServiceRedeem.ResultReturnCode.Success OrElse _
           serviceResponse.GiftcardLookupResult Is Nothing OrElse _
           String.IsNullOrEmpty(serviceResponse.GiftcardLookupResult.CouponOrGiftCard) Then
            response.Exception = True
            Return False
        End If

        '-----------------------------------------------------------------------
        ' No errors found.
        '-----------------------------------------------------------------------
        response.Exception = False
        Return True

    End Function

#End Region

#Region "Map"

    ''' ------------------------------------------------------------------------
    ''' <summary>
    ''' 
    '''      Method:  Map
    ''' 
    ''' Description:  Returns a redemption service Result object mapped to a
    '''               ResultCoupon object.
    ''' 
    ''' </summary>
    ''' <param name="serviceResult"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' ------------------------------------------------------------------------
    Private Function Map(ByVal serviceResult As WSRedemptionServiceRedeem.Result) As ResultCoupon

        Dim result As New ResultCoupon

        If serviceResult IsNot Nothing Then

            With serviceResult

                result.DateTime = .DateTime
                result.Description = .Description
                result.ReferenceCode = .ReferenceCode
                result.ReturnCode = .ReturnCode
                result.Server = .Server
                result.Source = .Source
                result.Type = .Type

                If serviceResult.ExceptionInfo IsNot Nothing Then
                    result.ExceptionInfo = New ResultExceptionInfoCoupon
                    result.ExceptionInfo.Code = .ExceptionInfo.Code
                    result.ExceptionInfo.Message = .ExceptionInfo.Message
                    result.ExceptionInfo.StackTrace = .ExceptionInfo.StackTrace
                    result.ExceptionInfo.Type = .ExceptionInfo.Type
                End If

            End With

        End If

        Return result

    End Function

#End Region

End Class
