Imports EDSL.Entities
Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Configuration
Imports System.Data.Common
Public Class dbMainUserPage
    Private Shared strMainConnString As String = "MainConnString"
    Public Function GetItem(ByVal intPageUserID As Integer) As entUserPage
        Dim objMainPage As New entUserPage
        Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
        Try
            Using dbCommand As DbCommand = db.GetStoredProcCommand("MainAdminPageUserGet")
                db.AddInParameter(dbCommand, "PageUserID", DbType.Int64, intPageUserID)
                Dim oRecordset As IDataReader = db.ExecuteReader(dbCommand)
                While oRecordset.Read()
                    With objMainPage
                        .PageID = Convert.ToString(oRecordset("PageUserID"))
                        .PageName = Convert.ToString(oRecordset("PageUserName"))
                        .PageContent = Convert.ToString(oRecordset("PageUserContent"))
                        .PageTitle = Convert.ToString(oRecordset("PageUserTitle"))
                        .PageMetaName = Convert.ToString(oRecordset("PageUserMetaName"))
                        .PageMetaContent = Convert.ToString(oRecordset("PageUserMetaContent"))
                        .MetaTitle = Convert.ToString(oRecordset("PageUserMetaTitle"))
                        .MainImage = Convert.ToString(oRecordset("PageMainImage"))
                        .CategoryID = Convert.ToInt32(oRecordset("CategoryID"))
                        .BulletList = Convert.ToString(oRecordset("PageMainBullet"))
                        .Active = Convert.ToString(oRecordset("Active"))
                    End With
                End While
                oRecordset.Close()
            End Using
            Return objMainPage
        Catch ex As Exception
            Throw ex
            Return Nothing
        End Try
    End Function
    ''' <summary>
    ''' Returns the page for the front end with the style 
    ''' </summary>
    ''' <param name="intPageUserID"></param>
    ''' <returns>User page object</returns>
    ''' <remarks></remarks>
    Public Function GetWithCategoryStyle(ByVal intPageUserID As Integer) As entUserPage
        Dim objMainPage As New entUserPage
        Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
        Try
            Using dbCommand As DbCommand = db.GetStoredProcCommand("MainPageUserWithStyleGet")
                db.AddInParameter(dbCommand, "PageUserID", DbType.Int64, intPageUserID)
                Dim oRecordset As IDataReader = db.ExecuteReader(dbCommand)
                While oRecordset.Read()
                    With objMainPage
                        .PageID = Convert.ToString(oRecordset("PageUserID"))
                        .PageName = Convert.ToString(oRecordset("PageUserName"))
                        .PageContent = Convert.ToString(oRecordset("PageUserContent"))
                        .PageTitle = Convert.ToString(oRecordset("PageUserTitle"))
                        .PageMetaName = Convert.ToString(oRecordset("PageUserMetaName"))
                        .PageMetaContent = Convert.ToString(oRecordset("PageUserMetaContent"))
                        .MetaTitle = Convert.ToString(oRecordset("PageUserMetaTitle"))
                        .MainImage = Convert.ToString(oRecordset("PageMainImage"))
                        .CategoryID = Convert.ToInt32(oRecordset("CategoryID"))
                        .BulletList = Convert.ToString(oRecordset("PageMainBullet"))
                        .Active = Convert.ToString(oRecordset("Active"))
                        .DropDownValue = Convert.ToString(oRecordset("DropDownValue"))
                    End With
                End While
                oRecordset.Close()
            End Using
            Return objMainPage
        Catch ex As Exception
            Throw ex
            Return Nothing
        End Try
    End Function
    
    Public Function GetAll(ByVal strWHEREclause As String, ByVal strORDERBYclause As String) As List(Of entUserPage)
        Dim objMainPage As New List(Of entUserPage)
        Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
        Try
            Using dbCommand As DbCommand = db.GetStoredProcCommand("MainAdminPageUserGetAll")
                db.AddInParameter(dbCommand, "WHEREclause", DbType.String, strWHEREclause)
                db.AddInParameter(dbCommand, "ORDERBYclause", DbType.String, strORDERBYclause)
                Dim oRecordset As IDataReader = db.ExecuteReader(dbCommand)
                While oRecordset.Read()
                    objMainPage.Add(New entUserPage() With { _
                      .PageID = Convert.ToInt32(oRecordset("PageUserID")), _
                      .PageName = Convert.ToString(oRecordset("PageUserName")), _
                      .PageContent = Convert.ToString(oRecordset("PageUserContent")), _
                      .PageTitle = Convert.ToString(oRecordset("PageUserTitle")), _
                      .PageMetaName = Convert.ToString(oRecordset("PageUserMetaName")), _
                      .PageMetaContent = Convert.ToString(oRecordset("PageUserMetaContent")), _
                      .MetaTitle = Convert.ToString(oRecordset("PageUserMetaTitle")), _
                      .MainImage = Convert.ToString(oRecordset("PageMainImage")), _
                      .CategoryID = Convert.ToInt32(oRecordset("CategoryID")), _
                      .BulletList = Convert.ToString(oRecordset("PageMainBullet")), _
                      .Active = Convert.ToString(oRecordset("Active")) _
                    })
                End While
                oRecordset.Close()
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return objMainPage
    End Function
    Public Function DeleteItem(ByVal intID As Integer, ByVal intUserID As Integer) As Boolean
        Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
        Try
            Using dbCommand As DbCommand = db.GetStoredProcCommand("MainAdminPageUserDELETE")
                db.AddInParameter(dbCommand, "PageUserID", DbType.Int16, intID)
                db.AddInParameter(dbCommand, "UserID", DbType.Int16, intUserID)
                db.ExecuteNonQuery(dbCommand)
            End Using
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Function SaveItem(ByVal intPageUserID As Integer, ByVal strPageUserTitle As String, ByVal strPageUserContent As String, ByVal strPageUserMetaName As String, ByVal strPageUserMetaContent As String, ByVal strPageMainMetaTitle As String, ByVal strMainImage As String, ByVal intActive As Integer, ByVal intUserID As Integer, ByVal categoryID As Integer, ByVal strBulletList As String) As Integer
        Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
        Dim strSPName As String = ""
        Try
            If intPageUserID = 0 Then
                strSPName = "MainAdminPageUserINSERT"
            Else
                strSPName = "MainAdminPageUserUPDATE"
            End If
            Using dbCommand As DbCommand = db.GetStoredProcCommand(strSPName)
                If intPageUserID <> 0 Then
                    db.AddInParameter(dbCommand, "PageUserID", DbType.Int16, intPageUserID)
                End If
                db.AddInParameter(dbCommand, "PageUserTitle", DbType.String, strPageUserTitle)
                db.AddInParameter(dbCommand, "PageUserContent", DbType.String, strPageUserContent)
                db.AddInParameter(dbCommand, "PageUserMetaName", DbType.String, strPageUserMetaName)
                db.AddInParameter(dbCommand, "PageUserMetaContent", DbType.String, strPageUserMetaContent)
                db.AddInParameter(dbCommand, "PageMainImage", DbType.String, strMainImage)
                db.AddInParameter(dbCommand, "PageMainBullet", DbType.String, strBulletList)
                db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, categoryID)
                db.AddInParameter(dbCommand, "Active", DbType.Int16, intActive)
                db.AddInParameter(dbCommand, "UserID", DbType.Int16, intUserID)
                db.AddInParameter(dbCommand, "PageUserMetaTitle", DbType.String, strPageMainMetaTitle)

                db.ExecuteNonQuery(dbCommand)
            End Using
            Return 0
        Catch ex As Exception
            Return 1
        End Try
    End Function

    ''' <summary>
    ''' Get IT Services list
    ''' </summary>
    ''' <param name=""></param>
    ''' <param name=""></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetAllITServices(ByVal categoryID As Integer) As List(Of entUserPage)
        Dim objMainPage As New List(Of entUserPage)
        Dim db As Database = DatabaseFactory.CreateDatabase(strMainConnString)
        Try
            Using dbCommand As DbCommand = db.GetStoredProcCommand("projPagesITServices")
                db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, categoryID)
                Dim oRecordset As IDataReader = db.ExecuteReader(dbCommand)
                While oRecordset.Read()

                    objMainPage.Add(New entUserPage() With { _
                      .PageID = Convert.ToInt32(oRecordset("PageUserID")), _
                      .PageTitle = Convert.ToString(oRecordset("PageUserTitle")), _
                      .CategoryID = Convert.ToInt32(oRecordset("CategoryID")) _
                    })
                End While
                oRecordset.Close()
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return objMainPage
    End Function
End Class
