Imports Microsoft.VisualBasic

Public Class AffiliateHandler
  Implements IHttpHandler

  Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
    Get
      Return True
    End Get
  End Property

  Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
    Dim affiliate As String = GetAffiliateID(context.Request.Url.Host)
    Dim url As String = "https://Charter.com/Order/Localize.aspx?AffID=" & affiliate
    Redirect(url, True)
  End Sub

  Private Function GetAffiliateID(ByVal host As String) As String
    Select Case host.ToLower
      Case "hawkeyecomputers.charter.com"
        Return "420061"
                'Case "grantstv.charter.com"
                '  Return "420063"
      Case "gunbergs.charter.com return"
        Return "420070"
      Case "worldofcd-rom.charter.com"
        Return "420066"
      Case "merrillhouse.charter.com"
        Return "420064"
      Case "davisoncomputers.charter.com"
        Return "420067"
      Case "searsdealer.charter.com"
        Return "420069"
      Case "selecttechsolutions.charter.com"
        Return "420060"
      Case "ccstech.charter.com"
        Return "420073"
      Case "convergence.charter.com"
        Return "420075"
      Case "qrp.charter.com"
        Return "420076"
      Case "mt.charter.com"
        Return "420077"
      Case "newportwireless.charter.com"
        Return "420074"
      Case "oscars.charter.com"
        Return "420078"
      Case "stereovideo.charter.com"
        Return "420080"
      Case "tvvillage.charter.com"
        Return "420081"
      Case "flanders.charter.com"
        Return "420068"
      Case "excelltec.charter.com"
        Return "420085"
      Case "computersandmore.charter.com"
        Return "420084"
      Case "lebakkens.charter.com"
        Return "420065"
      Case "encore.charter.com"
        Return "420089"
      Case "millars.charter.com"
        Return "420087"
      Case "restainobunbury.charter.com"
        Return "420072"
      Case "nextbuy.charter.com"
        Return "420079"
      Case "bigrapidsfurniture.charter.com"
        Return "420090"
      Case "millbrook.charter.com"
        Return "420086"
      Case "clems.charter.com"
        Return "420092"
      Case "clydes.charter.com"
        Return "420094"
      Case "friendlycomputing.charter.com"
        Return "420053"
      Case "ringcc.charter.com"
        Return "420097"
      Case "computerwarehouse.charter.com"
        Return "420091"
      Case "midstate.charter.com"
        Return "420098"
      Case "computerplusrhi.charter.com"
        Return "420095"
      Case "powercomputingsolutions.charter.com"
        Return "420071"
      Case "whitelake.charter.com"
        Return "420103"
      Case "obc.charter.com"
        Return "420102"
      Case "ue.charter.com"
        Return "420100"
      Case "camicro.charter.com"
        Return "420099"
      Case "becco.charter.com"
        Return "420101"
      Case "dansaudiovideo.charter.com"
        Return "420104"
      Case "sureclick.charter.com"
        Return "420096"
      Case "sunrise-appliance.charter.com"
        Return "420106"
      Case "haarmann.charter.com"
        Return "420005"
      Case "brothersmain.charter.com"
        Return "420015"
      Case "pcsolutions.charter.com"
        Return "420016"
      Case "teamelectronics.charter.com"
        Return "420019"
      Case "victorylane.charter.com"
        Return "420020"
      Case "demo.charter.com"
        Return "112100"
      Case "moondog.charter.com"
        Return "420028"
      Case "wildwestreno.charter.com"
        Return "420027"
      Case "sunfirewireless.charter.com"
        Return "420029"
      Case "midmichigancomputers.charter.com"
        Return "420031"
      Case "cybertechsystems.charter.com"
        Return "420034"
      Case "vannoords.charter.com"
        Return "420030"
      Case "compucom.charter.com"
        Return "420032"
      Case "ThisIsCable.charter.com"
        Return "120300"
      Case "cam.charter.com"
        Return "420036"
      Case "vandenbergstereo.charter.com"
        Return "420035"
      Case "themacexchange.charter.com"
        Return "420033"
      Case "vonage.charter.com"
        Return "121800"
      Case "houting.charter.com"
        Return "420039"
      Case "macatawa.charter.com"
        Return "420038"
      Case "scscomputers.charter.com"
        Return "420040"
      Case "csss.charter.com"
        Return "420047"
      Case "computercountry.charter.com"
        Return "420046"
      Case "eaglecomputerservices.charter.com"
        Return "420050"
      Case "bunch.charter.com"
        Return "420049"
      Case "Cline.charter.com"
        Return "420051"
      Case "maskertimes.charter.com"
        Return "420044"
      Case "friendlycomputers.charter.com"
        Return "420053"
      Case "silicaappliance.charter.com"
        Return "420048"
      Case "grandcare.charter.com"
        Return "420045"
      Case "raystv.charter.com"
        Return "420037"
      Case "pcoutlet.charter.com"
        Return "420052"
      Case "seckora.charter.com"
        Return "420054"
      Case "gta.charter.com"
        Return "420057"
      Case "virtualpcs.charter.com"
        Return "420056"
      Case "efcom.charter.com"
        Return "420055"
      Case "frs.charter.com"
        Return "420062"
      Case "ctswisconsin.charter.com"
        Return "420059"
      Case "pittco.charter.com"
        Return "420058"
      Case "circuitsplus.charter.com"
        Return "420011"
      Case Else
        ' if not matched with any of above affiliates return charters affiliate
        Return "118700"
    End Select
  End Function

  Private Sub Redirect(ByVal url As String, ByVal endResponse As Boolean)

    Dim context As System.Web.HttpContext = System.Web.HttpContext.Current

    If Not context Is Nothing Then

      If Not url.Equals(String.Empty) Then

        context.Response.Status = "301 Moved Permanently"
        context.Response.AddHeader("Location", url)

        If endResponse Then
          context.Response.End()
        End If
      End If

    End If

  End Sub


End Class
