From caed01998178469d25775f5e9914c311b0b955c7 Mon Sep 17 00:00:00 2001 From: Jonathan Alexis Perez Morales Date: Tue, 5 Sep 2023 17:36:42 -0700 Subject: [PATCH] --Metodo para obtener productos en API JAM --- App_Code/ClsInventarios.vb | 19 +++++++++ Ashx/E119.ashx | 80 +++++++++++++++++++++++++++----------- 2 files changed, 77 insertions(+), 22 deletions(-) diff --git a/App_Code/ClsInventarios.vb b/App_Code/ClsInventarios.vb index 3fb9d858b..502282246 100644 --- a/App_Code/ClsInventarios.vb +++ b/App_Code/ClsInventarios.vb @@ -5984,6 +5984,25 @@ Public Class ClsInventarios Return Retorno End Function + + Public Function GetJAM_APIs(Optional Opcion As Integer = 1) As Boolean + Dim Retorno As Boolean = False + Dataset = New DataSet() + DataAdapter("PA_JAM_APIs") + With SqlAdapter.SelectCommand.Parameters + .Add("@Opcion", SqlDbType.Int).Value = Opcion + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al obtener los productos.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + Return Retorno + + End Function #End Region diff --git a/Ashx/E119.ashx b/Ashx/E119.ashx index e7e3a11f0..07a7adc94 100644 --- a/Ashx/E119.ashx +++ b/Ashx/E119.ashx @@ -47,17 +47,6 @@ Public Class E119 : Implements IHttpHandler End If End Get End Property - Public ReadOnly Property TokenAutorizacion As String - Get - Return "$2y$10$LGqtRWUloKQmAt.jcUldc.PmS5LJ6l.WU2w1G4PBOTLMVKZRNQFPS" - End Get - End Property - - Public ReadOnly Property URLBase As String - Get - Return "https://services.fidelityapps.mx/" - End Get - End Property #Region "V A L I D A - D A T O S" @@ -99,19 +88,31 @@ Public Class E119 : Implements IHttpHandler Dim retorno As String = "" Try Dim Metodo = If(context.Request("Metodo") = Nothing, "", context.Request("Metodo").ToString()) - 'OBTENER EXISTENCIAS - 'If Metodo = "BASF_POG40" Then - ' context.Response.ContentType = "application/json" - ' Dim Auth = ValidarSolicitud(context) - ' If Auth.IsSucces Then - ' retorno = ConsultaDatos(context) - ' Else - ' context.Response.StatusCode = Auth.StatusCode - ' retorno = JsonConvert.SerializeObject(Auth.ErrorMessage) - ' End If + If Metodo = "BASF_POG40" Then + context.Response.ContentType = "application/json" + Dim Auth = ValidarSolicitud(context) - 'End If + If Auth.IsSucces Then + retorno = ConsultaDatos(context) + Else + context.Response.StatusCode = Auth.StatusCode + retorno = JsonConvert.SerializeObject(Auth.ErrorMessage) + End If + + End If + + If Metodo = "ConsultarProductos" Then + context.Response.ContentType = "application/json" + Dim Auth = ValidarSolicitud(context) + + If Auth.IsSucces Then + retorno = ConsultaProductos(context) + Else + context.Response.StatusCode = Auth.StatusCode + retorno = JsonConvert.SerializeObject(Auth.ErrorMessage) + End If + End If context.Response.Write(retorno) @@ -220,6 +221,41 @@ Public Class E119 : Implements IHttpHandler End If End Function + Private Function ConsultaProductos(ByVal context As HttpContext) As String + Dim Respuesta As New ResponseMsg + Dim RespuestaError As New ResponseMsgError + Dim TieneError As Boolean = False + + Dim Productos As JArray = Nothing + + Using ObjInventario As New ClsInventarios + If ObjInventario.GetJAM_APIs(1) AndAlso ObjInventario.DtResultados IsNot Nothing Then + Productos = JArray.Parse(ObjInventario.DtResultados.DataTableToJSONIPP()) + Else + RespuestaError.message = "no se pudo obtener los datos" + TieneError = True + End If + End Using + + Dim Msg As String = "Información día " & Now.ToShortDateString & If(RespuestaError.message <> "", " Error: " & RespuestaError.message, "") + Msg.GuardaLogAD("LogE119") + + If TieneError Then + context.Response.StatusCode = 200 + Return JsonConvert.SerializeObject(RespuestaError) + Else + context.Response.StatusCode = 200 + Try + Respuesta.data = New JObject(New JProperty("Productos", Productos)) + Respuesta.message = "Los datos se obtuvieron correctamente" + Return JsonConvert.SerializeObject(Respuesta) + Catch ex As Exception + RespuestaError.message = "Ocurrió un error al generar la petición" + Return JsonConvert.SerializeObject(RespuestaError) + End Try + End If + End Function + Private Class ResponseMsg Sub New() status = "success"