Imports dGen.Library.Enums.QueryEnums.QueryOperatorEnum
Imports dGen.Library.Enums.QueryEnums.CompareEnum
Partial Class ConcursoPostulanteDbHelper

#Region "Metodos Personalizados"

    Public Function ExecuteCopiaPostulacion(idConcursoPostulante As Integer, idUsuario As Integer) As MSG
        Dim msg As New MSG("ExecuteCopiaPostulacion")

        Try
            Dim QueryObject = Me.CreateQueryObject

            'QueryObject.CreateQuery("declare @paramOutput")
            QueryObject.CreateQuery("execute CopiaPostulacion @idConcursoPostulante, @idUsuario")
            QueryObject.AddParameter("@idConcursoPostulante", SqlDbType.Int, idConcursoPostulante)
            QueryObject.AddParameter("@idUsuario", SqlDbType.Int, idUsuario)

            msg = QueryObject.ExecuteNonQuery
            Return msg
        Catch ex As Exception
            msg.FriendlyMessage = "No fue posible guardar la informacion de la postulación"
            msg.TechnicalMessage = ex.Message
            Return msg
        End Try

    End Function
    ' Definir en esta region los metodos personalizados para el DbHelper
    Public Function ExistePostulacion(idUsuario As Integer, idPlaza As Integer) As Boolean
        Dim QueryObject = CreateQueryObject()
        QueryObject.CreateQuery("Select 1 from ConcursoPostulante")
        QueryObject.Where(_None, _Equals).idUsuario = idUsuario
        QueryObject.Where(_And, _Equals).idPlaza = idPlaza
        Return CBool(QueryObject.ExecuteScalar())
    End Function

    Public Function GetConcursoPostulante(idUsuario As Integer, idPlaza As Integer) As ConcursoPostulante
        Dim QueryObject = CreateQueryObject()
        QueryObject.CreateQuery(0)
        QueryObject.Where(_None, _Equals).idUsuario = idUsuario
        QueryObject.Where(_And, _Equals).idPlaza = idPlaza
        Return QueryObject.ExecuteEntity
    End Function

    Public Function ExisteCodigo(CodigoPostulante As String, idPlaza As Integer) As Boolean
        Dim QueryObject = CreateQueryObject()
        QueryObject.CreateQuery("Select 1 from ConcursoPostulante")
        QueryObject.Where(_None, _Equals).CodigoPostulante = CodigoPostulante
        QueryObject.Where(_And, _Equals).idPlaza = idPlaza
        Return CBool(QueryObject.ExecuteScalar())
    End Function

#End Region
End Class
