Exemplo n.º 1
0
        public async Task <IActionResult> SearchRoom([FromBody] GeneralDto info)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var result = await _hotelService.GetResponseSearch(info.InformationProvider, info.GeneralHotelInfo);

                if (result != null)
                {
                    return(Ok(result.Rooms));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (ProviderNotResponseException exProv)
            {
                return(GetUnavailableService(exProv, info));
            }
            catch (Exception)
            {
                return(GetErrorServerCode());
            }
        }
Exemplo n.º 2
0
        private async Task <object> GetResponseProviderService(GeneralDto generalDto, string type)
        {
            var router = await _routerRepository.GetMetadata(generalDto.InformationProvider);

            if (router != null)
            {
                var url = $"{router.Endpoint}/{router.TipoAdaptador}/Provider/{router.TipoProveedor}/{type}";
                _logger.LogInformation($"URL_SENDED {url}");

                var result = await Post(url, generalDto);

                if (result.IsSuccessStatusCode)
                {
                    return(await result.Content.ReadAsStringAsync());
                }
                else if (result.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable)
                {
                    throw new ProviderNotResponseException(await result.Content.ReadAsStringAsync());
                }
                else
                {
                    _logger.LogInformation(await result.Content.ReadAsStringAsync(), "ERROR_CONSUMING_SERVICE ", new object[] { url });
                    throw new System.Exception($"StatusCode {result.StatusCode.ToString()}, error {result.Content.ReadAsStringAsync()}");
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> SearchFlight([FromBody] GeneralDto info)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var result = await transportServices.Search(info.GeneralFlightInfo.SearchFlight, info.InformationProvider);

                if (result == null)
                {
                    return(NoContent());
                }
                else
                {
                    if (result.Any())
                    {
                        return(Ok(result.FirstOrDefault().Flights));//Se devuelve solo el listado de transportes
                    }
                    else
                    {
                        return(Ok(result));
                    }
                }
            }
            catch (ProviderNotResponseException exProv)
            {
                return(GetUnavailableService(exProv, info));
            }
            catch (Exception)
            {
                return(GetErrorServerCode());
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> BookFlight([FromBody] GeneralDto info)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var result = await _fligthManager.GetResponseBook(info.InformationProvider, info.GeneralFlightInfo);

                if (result != null)
                {
                    return(Ok(result.BookFlightResponse));
                }
                return(NotFound());
            }
            catch (ProviderNotResponseException exProv)
            {
                return(GetUnavailableService(exProv, info));
            }
            catch (Exception)
            {
                return(GetErrorServerCode());
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> SearchFlight([FromBody] GeneralDto info)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var result = await _fligthManager.GetResponseSearch(info.InformationProvider, info.GeneralFlightInfo);

                if (result != null && result.Trip.Any())
                {
                    return(Ok(result.Trip.FirstOrDefault().Flights));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (ProviderNotResponseException exProv)
            {
                return(GetUnavailableService(exProv, info));
            }
            catch (Exception)
            {
                return(GetErrorServerCode());
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> BookShow([FromBody] GeneralDto info)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var result = await _showService.GetResponseBook(info.InformationProvider, info.GeneralShowInfo);

                if (result == null)
                {
                    return(NotFound());
                }
                else
                {
                    return(Ok(result.ShowReservationResponse));
                }
            }
            catch (ProviderNotResponseException exProv)
            {
                return(GetUnavailableService(exProv, info));
            }
            catch (Exception)
            {
                return(GetErrorServerCode());
            }
        }
Exemplo n.º 7
0
        public async Task <IActionResult> BookFlight([FromBody] GeneralDto info)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var result = await transportServices.Book(info.GeneralFlightInfo.BookFlight, info.InformationProvider);

                return(Ok(result));
            }
            catch (ProviderNotResponseException exProv)
            {
                return(GetUnavailableService(exProv, info));
            }
            catch (Exception)
            {
                return(GetErrorServerCode());
            }
        }
Exemplo n.º 8
0
        public async Task <IActionResult> SearchShow([FromBody] GeneralDto info)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var result = await showServices.Search(info.GeneralShowInfo.SearchShow, info.InformationProvider);

                return(Ok(result));
            }
            catch (ProviderNotResponseException exProv)
            {
                return(GetUnavailableService(exProv, info));
            }
            catch (Exception)
            {
                return(GetErrorServerCode());
            }
        }
Exemplo n.º 9
0
 public async Task <object> Search(GeneralDto generalDto)
 {
     return(await GetResponseProviderService(generalDto, "search"));
 }
Exemplo n.º 10
0
 public async Task <object> Book(GeneralDto generalDto)
 {
     return(await GetResponseProviderService(generalDto, "book"));
 }
Exemplo n.º 11
0
 private IActionResult GetUnavailableService(ProviderNotResponseException exProv, GeneralDto info)
 {
     return(StatusCode(StatusCodes.Status503ServiceUnavailable, string.Format(exProv.Message, info.InformationProvider.IdProvider, info.InformationProvider.ProviderName)));
 }