Imports System.Net
Imports System.Net.Http
Imports System.Net.Security
Imports Newtonsoft.Json

Public Class VAAPBCpers
    Inherits System.Web.UI.Page
    'Shared sessionUsuario As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("Persona") Is Nothing Then
            Response.Redirect("default.aspx")
        End If
        If Session("modo") = "PERSONAL" Then
            'intPicadaBL.Visible = False
            'bolsaDeHorasBL.Visible = False
            'VAAPBCBL.Visible = False
            'informPicadasBL.Visible = False
        End If
        If Session("modo") = "PROPIO" Then
            Li1.Visible = False
        End If

        'sessionUsuario = Session("usuario")
        inpAnyoVAAPBC.Value = DateTime.Now.ToString("yyyy")
    End Sub
    <System.Web.Services.WebMethod()>
    Public Shared Async Function VacacionesAsuntos(anyo As String) As Threading.Tasks.Task(Of String)
        Dim sessionUsuario As String = HttpContext.Current.Session("usuario")
        'Dim url3 As String = "https://172.16.89.216:81/api/SituacionVAAPBC?Nif=28466610Q&Anno=2022"
        '  Dim url3 As String = "https://192.168.41.122/api/SituacionVAAPBC?Nif=28466610Q&Anno=2022"
        Dim usuariosSeleccionados As List(Of String) = HttpContext.Current.Session("usuariosSeleccionados")
        Dim consulta As New Models.ConsultaAnnoMes
        consulta.listaNif = usuariosSeleccionados
        consulta.Anno = anyo

        'Dim url3 As String = ConfigurationManager.AppSettings("RutaRes").ToString + "/api/SituacionVAAPBC"

        Dim jsonConsulta As String = JsonConvert.SerializeObject(consulta)
        Dim url As String = ConfigurationManager.AppSettings("RutaRes").ToString + "/api/SituacionVAAPBC"
        Dim clienteHTTP As New HttpClient
        Dim contenidoConsultaHTTP As New StringContent(jsonConsulta, Encoding.UTF8, "application/json")
        Debug.WriteLine("CargarListadodePicadasAsync:1===" + Now.ToLongTimeString)
        Dim respuestaHTTP As HttpResponseMessage = Await clienteHTTP.PostAsync(url, contenidoConsultaHTTP).ConfigureAwait(False)
        Debug.WriteLine("CargarListadodePicadasAsync:2===" + Now.ToLongTimeString)
        Dim sRespuesta As String = Await respuestaHTTP.Content.ReadAsStringAsync().ConfigureAwait(False)
        Debug.WriteLine("CargarListadodePicadasAsync:3===" + Now.ToLongTimeString)
        Dim settings As New Newtonsoft.Json.JsonSerializerSettings()
        settings.CheckAdditionalContent = True


        'ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(Function() True)
        'Dim clienteHTTP3 As New Net.WebClient()
        'clienteHTTP3.Encoding = System.Text.Encoding.UTF8
        'Dim respuesta3 As String
        'respuesta3 = clienteHTTP3.DownloadString(url3)

        Dim deserializador3 As New System.Web.Script.Serialization.JavaScriptSerializer()
        deserializador3.MaxJsonLength = Integer.MaxValue
        Dim listaNominas As Models.ResultadoSituacionVAAPBC =
            deserializador3.Deserialize(Of Models.ResultadoSituacionVAAPBC)(sRespuesta)
        Dim json = ""
        Dim sbResultado As New Text.StringBuilder

        Return sRespuesta

        'If listaNominas.Resultado = 0 Then

        '    listaNominas.DiasVAB.ListadoVaApBc.Sort(Function(x, y) x.Fecha.CompareTo(y.Fecha))
        '    json += "[{""resultado"":""" + listaNominas.Resultado.ToString + """,""ListadoVAAPBC"":["
        '    Dim cont = 0
        '    If Not listaNominas.DiasVAB.ListadoVaApBc.Count = 0 Then
        '        For Each listadoVAAPCBC As Models.VaApBc In listaNominas.DiasVAB.ListadoVaApBc
        '            If cont > 0 Then
        '                json += ","
        '            End If
        '            cont += 1
        '            json += "{""Descripcion"":""" + listadoVAAPCBC.Descripcion + """,""FechaIni"":""" + listadoVAAPCBC.Fecha + """,""FechaFin"":""" + listadoVAAPCBC.FechaFin + """,""TotalDias"":""" + listadoVAAPCBC.NumDias.ToString + """,""HorasManana"":""" + listadoVAAPCBC.HorasManana + """,""HorasTarde"":""" + listadoVAAPCBC.HorasTarde + """}"
        '        Next
        '    End If
        '    json += "],"
        '    json += """TotPerVa"":""" + listaNominas.DiasVAB.TotPerVa + """,""TotDisVa"":""" + listaNominas.DiasVAB.TotDisVa + """,""TotDifVa"":""" + listaNominas.DiasVAB.TotDifVa + """," +
        '    """TotPerAp"":""" + listaNominas.DiasVAB.TotPerAp + """,""TotDisAp"":""" + listaNominas.DiasVAB.TotDisAp + """,""TotDifAp"":""" + listaNominas.DiasVAB.TotDifAp + """," +
        '    """TotPerBc"":""" + listaNominas.DiasVAB.TotPerBc + """,""TotDisBc"":""" + listaNominas.DiasVAB.TotDisBc + """,""TotDifBc"":""" + listaNominas.DiasVAB.TotDifBc + """," +
        '    """TotPerDr"":""" + listaNominas.DiasVAB.TotPerDr + """,""TotDisDr"":""" + listaNominas.DiasVAB.TotDisDr + """,""TotDifDr"":""" + listaNominas.DiasVAB.TotDifDr + """," +
        '    """TotPerHr"":""" + listaNominas.DiasVAB.TotPerHr + """,""TotDisHr"":""" + listaNominas.DiasVAB.TotDisHr + """,""TotDifHr"":""" + listaNominas.DiasVAB.TotDifHr + """}]"
        'Else
        '    json += "[{""resultado"":""" + listaNominas.Resultado.ToString + """}]"
        'End If






    End Function
End Class