Imports Newtonsoft.Json
Imports System.Net.Http
Imports System.Net.Http.Headers
Imports WebIntranet.ClasesDatosAdmin
Public Class docencia
    Inherits System.Web.UI.Page

    Protected Async Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim vidaAdministrativaItems As New List(Of WebIntranet.ClasesDatosAdmin.DOCENCIA)
        Dim TiposActos As New List(Of TIPOAPTOSADMINISTRATIVOS)
        Dim token As String = Session("token")
        Dim client As New HttpClient()
        client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Bearer", token)
        client.BaseAddress = New Uri(ConfigurationManager.AppSettings("SwaggerVB"))
        Dim idPers = Session("persona").Personas(0).idPersona
        Dim response = Await client.GetAsync("/api/DOCENCIA/docenciaspersona/" + idPers.ToString)

        If response.IsSuccessStatusCode Then
            Dim resultContent = Await response.Content.ReadAsStringAsync()
            vidaAdministrativaItems = If(JsonConvert.DeserializeObject(Of List(Of WebIntranet.ClasesDatosAdmin.DOCENCIA))(resultContent), New List(Of WebIntranet.ClasesDatosAdmin.DOCENCIA)())
            vidaAdministrativaItems = vidaAdministrativaItems.ToList()
        Else
            Console.WriteLine($"Error al cargar Vida Administrativa: {response.StatusCode}")
        End If
        Dim htmlTabla = ""
        If vidaAdministrativaItems.Count > 0 Then


            htmlTabla += "<table class='tablaPicadas'>" +
                         "<tr><th>Denominación</th>" +
                         "<th>Centro</th>" +
                         "<th>Fecha</th>" +
                         "<th>Duración</th>" +
                         "<th>Tipo de docencia</th></tr>"
            For Each itm As WebIntranet.ClasesDatosAdmin.DOCENCIA In vidaAdministrativaItems
                '/fichero.aspx?id=" + linAd.IDLINEAVIDAADMIN.ToString() + "&cl=" + tsl5.crypt.SHA1("M3Soft." & linAd.IDLINEAVIDAADMIN.ToString) + "&t=LINEAVIDAADMINISTRATIVA
                Dim urlFich = "/fichero.aspx?id=" + itm.IDDOCENCIA.ToString() + "&cl=" + tsl5.crypt.SHA1("M3Soft." & itm.IDDOCENCIA.ToString) + "&t=DOCENCIA"
                'Dim urlFich = "/Ficheros?tip=VerFrm&id=" + itm.ToString()
                htmlTabla += "<tr>"
                htmlTabla += "<td>" + If(itm.RUTA IsNot Nothing, "<a href='" + urlFich + "' target='_blank'>" + itm.DENOMINACION + "</a>", itm.DENOMINACION) + "</td>"
                htmlTabla += "<td>" + itm.CENTRO + "</td>"
                htmlTabla += "<td>" + If(itm.FECHAEXPEDICION IsNot Nothing, itm.FECHAEXPEDICION.ToString.Substring(0, 10), "") + "</td>"
                htmlTabla += "<td style='text-align:center'>" + itm.DURACION.ToString() + "</td>"
                htmlTabla += "<td style='text-align:center'>" + itm.IDTIPODOCENCIANavigation.DESCRIPCION + "</td></tr>"
                'htmlTabla += "<td style='text-align:center'>" + If(itm.OFICIAL = True, "<i class=""fa fa-check""></i>", "") + "</td>"
            Next
            htmlTabla += "</table>"
        Else
            htmlTabla += "<p style='color:red;font-weight:bold'>No se han encontrado resultados</p>"
        End If
        divTabla.InnerHtml = htmlTabla
    End Sub

End Class