Exemplo n.º 1
0
        public IActionResult ConsultarVuelosUiid(string uuid)
        {
            try
            {
                if (string.IsNullOrEmpty(uuid))
                {
                    return(BadRequest());
                }
                else
                {
                    ServidorCache servidorCache = new ServidorCache(_loggercache);
                    var           vuelos        = servidorCache.getCache(uuid + "_FLIGHTS" + "_CATALOG");

                    if (vuelos != null)
                    {
                        Logger.LogInformation("Se obtiene respuesta de normalizador :" + vuelos);
                        Logger.LogInformation($"Contiene {vuelos.providersResponse.Count} proveedores la respuesta");
                        if (vuelos.providersResponse.Count > 0)
                        {
                            List <ResponseBaseVuelos> responseVuelos = new List <ResponseBaseVuelos>();
                            foreach (var item in vuelos.providersResponse)
                            {
                                Logger.LogInformation($"proveedor {item}");
                                if (!string.IsNullOrEmpty(item.code) && !string.IsNullOrEmpty(item.destination) && !string.IsNullOrEmpty(item.origin) && !string.IsNullOrEmpty(item.startDate) && !string.IsNullOrEmpty(item.endDate) && !string.IsNullOrEmpty(item.price) && !string.IsNullOrEmpty(item.providerName))
                                {
                                    Logger.LogInformation($"proveedor valido");
                                    Logger.LogInformation($"Ciudad origen {item.origin}");
                                    Logger.LogInformation($"Ciudad destino {item.destination}");
                                    var origen  = _db.Aeropuertos.FirstOrDefault(c => c.Lata == item.origin);
                                    var destino = _db.Aeropuertos.FirstOrDefault(c => c.Lata == item.destination);
                                    if (origen != null && destino != null)
                                    {
                                        DateTime stardate = DateTime.Parse(item.startDate);
                                        Logger.LogInformation($"origen y destino validos");
                                        responseVuelos.Add(new ResponseBaseVuelos
                                        {
                                            OriginAirport      = origen.Lata,
                                            DestinationAirport = destino.Lata,
                                            Destination        = destino.CiudadUbicacin,
                                            Origin             = origen.CiudadUbicacin,
                                            Stardate           = DateTime.Parse(item.startDate),
                                            EndDate            = DateTime.Parse(item.endDate),
                                            FligthCode         = item.code,
                                            Price    = item.price,
                                            Supplier = item.providerName
                                        });
                                        Logger.LogInformation($"proveedor agregado correctamente");
                                    }
                                    else
                                    {
                                        Logger.LogInformation($"origen y destino invalidos");
                                    }
                                }
                                else
                                {
                                    Logger.LogInformation($"proveedor invalido");
                                }
                            }
                            return(Ok(responseVuelos));
                        }
                        else
                        {
                            return(NotFound("No existen proveedores disponibles para esta solicitud"));
                        }
                    }
                    else
                    {
                        return(NotFound("No se encontro informacion con este Uuid"));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Excepcion generada en ConsutlarVuelosUuid: " + ex.Message);
                return(StatusCode(500, "Ocurrio un error"));

                throw;
            }
        }
Exemplo n.º 2
0
        public IActionResult ConsultarReservaUiid(string uuid, string nombre, string apellido, string codigoVuelo)
        {
            try
            {
                Logger.LogInformation("INICIA PROCESO DE RESERVA DE VUELO");
                JwtProvider jwt         = new JwtProvider("TouresBalon.com", "UsuariosPlataforma");
                var         accessToken = Request.Headers[HeaderNames.Authorization];
                var         first       = accessToken.FirstOrDefault();
                if (string.IsNullOrEmpty(accessToken) || !first.Contains("Bearer"))
                {
                    return(BadRequest());
                }
                string token = first.Replace("Bearer", "").Trim();
                Logger.LogInformation("INICIA PROCESO DE VALIDACION DE TOKEN :" + token);
                var a = jwt.ValidateToken(token);
                if (!a)
                {
                    return(Unauthorized());
                }
                if (string.IsNullOrEmpty(uuid))
                {
                    return(BadRequest("Ingrese uuid"));
                }
                if (string.IsNullOrEmpty(nombre))
                {
                    return(BadRequest("Ingrese nombre"));
                }
                if (string.IsNullOrEmpty(apellido))
                {
                    return(BadRequest("Ingrese apellido"));
                }
                else
                {
                    ServidorCache servidorCache = new ServidorCache(_loggercache);
                    var           vuelos        = servidorCache.getCacheReserva(uuid + "_FLIGHTS" + "_RESERVE");

                    if (vuelos != null)
                    {
                        Logger.LogInformation("Se obtiene respuesta de normalizador :" + vuelos);
                        Logger.LogInformation($"Contiene {vuelos.providersResponse.Count} proveedores la respuesta");
                        if (vuelos.providersResponse.Count > 0)
                        {
                            Random r = new Random();
                            var    x = r.Next(0, 1000000);
                            string s = x.ToString("000000");
                            List <ResponseBaseVuelosReserva> responseVuelos = new List <ResponseBaseVuelosReserva>();
                            foreach (var item in vuelos.providersResponse)
                            {
                                Logger.LogInformation($"proveedor {item}");
                                responseVuelos.Add(new ResponseBaseVuelosReserva
                                {
                                    Estado             = item.status,
                                    CodigoReservaVuelo = s
                                });
                                Logger.LogInformation($"proveedor agregado correctamente");
                            }
                            _db.ReservaVuelos.Add(new ReservaVuelo
                            {
                                Apellido      = apellido,
                                CodigoReserva = s,
                                CodigoVuelo   = codigoVuelo,
                                Nombre        = nombre,
                                Token         = token
                            });
                            _db.SaveChanges();
                            return(Ok(responseVuelos));
                        }
                        else
                        {
                            return(NotFound("No existen proveedores disponibles para esta solicitud"));
                        }
                    }
                    else
                    {
                        return(NotFound("No se encontro informacion con este Uuid"));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Excepcion generada en ConsutlarVuelosUuid: " + ex.Message);
                return(StatusCode(500, "Ocurrio un error"));

                throw;
            }
        }
Exemplo n.º 3
0
        public IActionResult ConsultarHotelesUiid([FromBody] ReservaConsultaHotelDTO model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.Uuid))
                {
                    return(BadRequest());
                }
                else
                {
                    ServidorCache servidorCache = new ServidorCache(_loggercache);
                    var           vuelos        = servidorCache.getCache(model.Uuid + "_HOTEL" + "_CATALOG");

                    if (vuelos != null)
                    {
                        Random   r             = new Random();
                        string[] Descripciones = new string[10];
                        Descripciones[1] = "Hotel con vista al mar perfecto para viaje de placer";
                        Descripciones[2] = "Hotel en la montaña para alejarse de la monotonia y conectarse con la naturaleza";
                        Descripciones[3] = "Hotel perfecto para viajes de negocio";
                        Descripciones[4] = "Hotel para la familia con actividadades ludicas para cualquier edad";
                        Descripciones[5] = "Hotel todo terreno, descanso, trabajo lo que quieras ven pero ya!";
                        Logger.LogInformation("Se obtiene respuesta de normalizador :" + vuelos);
                        Logger.LogInformation($"Contiene {vuelos.providersResponse.Count} proveedores la respuesta");
                        if (vuelos.providersResponse.Count > 0)
                        {
                            List <ResponseBaseHoteles> responseVuelos = new List <ResponseBaseHoteles>();
                            foreach (var item in vuelos.providersResponse)
                            {
                                Logger.LogInformation($"proveedor {item}");
                                if (!string.IsNullOrEmpty(item.code) && !string.IsNullOrEmpty(item.destination) && !string.IsNullOrEmpty(item.hotelname) && !string.IsNullOrEmpty(item.price) && !string.IsNullOrEmpty(item.providerName) && !string.IsNullOrEmpty(item.roomType))
                                {
                                    Logger.LogInformation($"proveedor valido");
                                    Logger.LogInformation($"Pais origen {"Colombia"}");
                                    Logger.LogInformation($"Ciudad destino {item.destination}");
                                    var destino = _db.Aeropuertos.FirstOrDefault(c => c.Lata == item.destination);
                                    if (destino != null)
                                    {
                                        DateTime stardate = DateTime.Parse(model.FechaInicio);
                                        DateTime endDate  = DateTime.Parse(model.FechaFinal);
                                        Logger.LogInformation($"origen y destino validos");
                                        responseVuelos.Add(new ResponseBaseHoteles
                                        {
                                            City        = destino.CiudadUbicacin,
                                            Description = Descripciones[r.Next(1, 10)],
                                            HotelCode   = item.code,
                                            HotelImage  = $"hotel{r.Next(1, 5)}​​​​​",
                                            Stardate    = stardate,
                                            EndDate     = endDate,
                                            Price       = item.price,
                                            Supplier    = item.providerName,
                                            HotelName   = item.hotelname
                                        });
                                        Logger.LogInformation($"proveedor agregado correctamente");
                                    }
                                    else
                                    {
                                        Logger.LogInformation($"origen invalido");
                                    }
                                }
                                else
                                {
                                    Logger.LogInformation($"proveedor invalido");
                                }
                            }
                            return(Ok(responseVuelos));
                        }
                        else
                        {
                            return(NotFound("No existen proveedores disponibles para esta solicitud"));
                        }
                    }
                    else
                    {
                        return(NotFound("No se encontro informacion con este Uuid"));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Excepcion generada en ConsutlarVuelosUuid: " + ex.Message);
                return(StatusCode(500, "Ocurrio un error"));

                throw;
            }
        }