Imports EDSL.Entities
Imports EDSL.DAL

Partial Public Class SidebarCaseStudy
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim caseStudyType As New Integer
        Dim productID As New Integer
        Dim categoryID As New Integer


        'Check that the page is category only

        If Request.QueryString("pid") = "" Then
            'Get the category
            If Request.QueryString("cid") <> "" Then
                caseStudyType = Convert.ToInt32(Request.QueryString("cid"))

                GetCaseStudyDetails(caseStudyType, 0, categoryID)
            End If

            If Request.QueryString("id") = "1" Then
                caseStudyType = Convert.ToInt32(Request.QueryString("id"))
                GetCaseStudyDetails(caseStudyType, 0, categoryID)
            End If
        Else
            caseStudyType = Convert.ToInt32(Request.QueryString("cid"))
            productID = Convert.ToInt32(Request.QueryString("pid"))

            GetCaseStudyDetails(caseStudyType, productID, categoryID)
        End If

    End Sub

    Private Sub GetCaseStudyDetails(ByVal id As Integer, ByVal productID As Integer, ByVal parentID As Integer)
        Dim func As New miscFunctions
        Dim main As New dbMainCaseStudy
        Dim caseStudy As New entMainCaseStudy
        If productID > 0 Then
            caseStudy = main.GetItemSideBar_Product(id, productID)
        Else
            caseStudy = main.GetItemSideBar(id)
        End If

        If Not caseStudy.CaseStudyID Is Nothing Then
            With caseStudy
                Dim objMainCategory As New entmainCategory
                Dim objMain As New dbMainCategory
                If parentID > 0 Then
                    objMainCategory = objMain.GetItem(parentID)
                Else
                    objMainCategory = objMain.GetItem(id)
                End If


                lnkViewAllArticles.NavigateUrl += ".html?cst=" & id.ToString()
                lnkCaseStudy.Text = .CaseStudyHeadline
                lnkCaseStudy.NavigateUrl = "~/casestudy/case-" + func.CleanUrlString(.CaseStudyHeadline) + "-" + id.ToString() + "-" + .CaseStudyID.ToString()
                lnkReadMore.NavigateUrl = "~/casestudy/case-" + func.CleanUrlString(.CaseStudyHeadline) + "-" + id.ToString() + "-" + .CaseStudyID.ToString()
                lblCaseStudyHeadLine.Text = .CaseStudySummary
                'If .ThumbImage <> "" Then
                '    imgCaseStudy.ImageUrl += .ThumbImage
                '    imgCaseStudy.NavigateUrl = "~/casestudy/casestudy-" + func.CleanUrlString(.CaseStudyHeadline) + "-" + id.ToString() + "-" + .CaseStudyID.ToString
                'Else
                '    imgCaseStudy.Visible = False
                'End If

            End With
        Else
            'Remove the user control from the page
            sideBar.Visible = False
        End If

    End Sub

End Class