Imports Newtonsoft.Json
Imports System.Net.Http
Imports System.Net.Http.Headers
Imports WebIntranet.ClasesDatosAdmin

Public Class Formacion
    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.FORMACION)
        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/FORMACION/formacionespersona/" + idPers.ToString)

        If response.IsSuccessStatusCode Then
            Dim resultContent = Await response.Content.ReadAsStringAsync()
            vidaAdministrativaItems = If(JsonConvert.DeserializeObject(Of List(Of WebIntranet.ClasesDatosAdmin.FORMACION))(resultContent), New List(Of WebIntranet.ClasesDatosAdmin.FORMACION)())
            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>Nombre curso</th>" +
                         "<th>Nombre</th>" +
                         "<th>Fecha expedición</th>" +
                         "<th>Duración</th>" +
                         "<th>Aprovechamiento</th>" +
                         "<th>Oficial</th></tr>"
            For Each itm As WebIntranet.ClasesDatosAdmin.FORMACION In vidaAdministrativaItems
                '/fichero.aspx?id=" + linAd.IDLINEAVIDAADMIN.ToString() + "&cl=" + tsl5.crypt.SHA1("M3Soft." & linAd.IDLINEAVIDAADMIN.ToString) + "&t=LINEAVIDAADMINISTRATIVA
                Dim urlFich = "/fichero.aspx?id=" + itm.IDFORMACION.ToString() + "&cl=" + tsl5.crypt.SHA1("M3Soft." & itm.IDFORMACION.ToString) + "&t=FORMACION"
                'Dim urlFich = "/Ficheros?tip=VerFrm&id=" + itm.ToString()
                htmlTabla += "<tr>"
                htmlTabla += "<td>" + If(itm.RUTA IsNot Nothing, "<a href='" + urlFich + "' target='_blank'>" + itm.NOMBRE_CURSO + "</a>", itm.NOMBRE_CURSO) + "</td>"
                htmlTabla += "<td>" + itm.CENTRO + "</td>"
                htmlTabla += "<td>" + If(itm.FECHA_EXPEDICION IsNot Nothing, itm.FECHA_EXPEDICION.ToString.Substring(0, 10), "") + "</td>"
                htmlTabla += "<td style='text-align:center'>" + itm.DURACION.ToString() + "</td>"
                htmlTabla += "<td style='text-align:center'>" + If(itm.APROVECHAMIENTO = True, "<i class=""fa fa-check""></i>", "") + "</td>"
                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