public List <DTO_GiniMachine> ObtenerJSON(DTO_GiniMachine dto_Entrada) { string xClase = string.Format("{0}|{1}", MethodBase.GetCurrentMethod().Module.Name, MethodBase.GetCurrentMethod().DeclaringType.Name); string xProceso = MethodBase.GetCurrentMethod().Name; var dto_excepcion = new UTL_TRA_EXCEPCION { STR_CLASE = xClase, STR_EVENTO = xProceso }; var dto = new DynamicDto(); dto.ParameterList = new List <SpParameter>(); dto.ParameterList.AddRange(from nodo in dto_Entrada.GetType().GetProperties() where nodo.GetValue(dto_Entrada) != null select new SpParameter { Name = nodo.Name, Value = nodo.GetValue(dto_Entrada).ToString() } ); dto.Result = null; dto.SPName = "usp_GeneraProspectoModeloGini"; var dto_result = new List <DTO_GiniMachine>(); try { var objRet = DynamicSqlDAO.ExecuterSp(dto, GlobalClass.connectionString.Where(a => a.Key == infDto.STR_COD_PAIS).FirstOrDefault().Value); if (objRet.HasResult) { dto_result = JsonConvert.DeserializeObject <List <DTO_GiniMachine> >(JsonConvert.SerializeObject(objRet.Result.Tables[0])); dto_result.FirstOrDefault().Mensaje = string.Concat("", dto_result.FirstOrDefault().Mensaje); } } catch (Exception ex) { dto_excepcion.STR_MENSAJE = ex.Message; DynamicSqlDAO.guardaExcepcion(dto_excepcion, ConfigurationManager.ConnectionStrings["TwoFunTwoMeConnection"].ConnectionString); dto_Entrada.Mensaje = "ERR"; } return(dto_result); }
public IHttpActionResult Procesar(DTO_GiniMachine objGiniMachine) { manager = new ManagerGiniMachine(); string xClase = string.Format("{0}|{1}", MethodBase.GetCurrentMethod().Module.Name, MethodBase.GetCurrentMethod().DeclaringType.Name); string xProceso = MethodBase.GetCurrentMethod().Name; string strHostName = System.Net.Dns.GetHostName(); IPHostEntry ipHostInfo = Dns.GetHostEntry(strHostName); IPAddress ipAddress = ipHostInfo.AddressList[0]; objGiniMachine.UsrCreacion = "WEB"; var dto_excepcion = new UTL_TRA_EXCEPCION { STR_CLASE = xClase, STR_EVENTO = xProceso, STR_APLICATIVO = ConfigurationManager.AppSettings["APLICATIVO"].ToString(), STR_SERVIDOR = ipAddress.ToString(), STR_PARAMETROS = JsonConvert.SerializeObject(objGiniMachine), FEC_CREACION = DateTime.Now }; var dto_ObjConfig = new DTO_GiniMachineConfig { Buro = "GINIMACHINE" }; try { #region CONFIGURACION GINIMACHINE dto_ObjConfig = manager.ObtenerConfigGiniMachine(dto_ObjConfig).FirstOrDefault(); #endregion #region OBTENER JSON INPUT objGiniMachine.Input = manager.ObtenerJSON(objGiniMachine).FirstOrDefault().Json; #endregion #region CONSUMIR REST GINIMACHINE RestClient cliente = new RestClient(dto_ObjConfig._EndPoint + dto_ObjConfig._Resource); // Dirección web del reporte RestRequest request = new RestRequest(); // Clase propia del RestSharp para asignar parámetros de envio. request.Method = Method.POST; request.AddHeader("Accept", "application/json"); request.AddParameter(dto_ObjConfig._ParamName1, dto_ObjConfig._ParamVal1, ParameterType.QueryString); request.AddParameter("application/json", objGiniMachine.Input, ParameterType.RequestBody); //request.AddJsonBody(objGiniMachine.Input); var respuesta = cliente.Execute(request); // Metodo que ejecuta la solicitud. if (respuesta.StatusCode == System.Net.HttpStatusCode.OK) // Si retorna OK, el reporte fue generado. { objGiniMachine.Output = respuesta.Content.ToString(); if (!string.IsNullOrEmpty(objGiniMachine.Output.ToString())) { if (objGiniMachine.Output.Contains("Approve") || objGiniMachine.Output.Contains("Decl")) { #region ALMACENAR OUTPUT BD objGiniMachine.ModelId = dto_ObjConfig._ParamVal1; objGiniMachine.Servidor = dto_ObjConfig._EndPoint; manager.GuardarResultadoGinimachine(objGiniMachine); objGiniMachine.Input = ""; #endregion objGiniMachine.Mensaje = "SUCCESS"; } } } else { String mensajeError = respuesta.Content; } #endregion } catch (Exception ex) { dto_excepcion.STR_MENSAJE = ex.Message; DynamicSqlDAO.guardaExcepcion(dto_excepcion, ConfigurationManager.ConnectionStrings["TwoFunTwoMeConnection"].ConnectionString); objGiniMachine.Status = "ERR"; objGiniMachine.Mensaje = ex.Message; } return(Json(objGiniMachine)); }