Esempio n. 1
0
        public async Task <bool> Book(BookFlightDto bookFlight, InformationProvider informationProvider)
        {
            //Obtiene la información de metadata y la lleva al modelo de metadata
            var metadataCofig = await _repository.GetMetadata(informationProvider, IMetadataRestRepository.RequestType.book);

            if (metadataCofig.Body != null || metadataCofig.Body != "")
            {
                var metadataFieldTransport = Newtonsoft.Json.JsonConvert.DeserializeObject <Entity.Transport.BookFlightDto>(metadataCofig.Body);
                //Convierte el objeto request en Json
                var body = Newtonsoft.Json.JsonConvert.SerializeObject(bookFlight, Newtonsoft.Json.Formatting.Indented);
                metadataCofig.Body = _fieldMapper.GetBodyMapped(metadataFieldTransport, body);
            }

            metadataCofig.Url = _fieldMapper.GetUrlMapped(bookFlight, metadataCofig.Url);
            var providerConsumer = new ProviderConsumerService(_consumer);

            var result = await providerConsumer.Request(metadataCofig);

            if (!result.IsSuccessStatusCode)
            {
                throw new ProviderNotResponseException();
            }

            var value = await result.Content.ReadAsStringAsync();

            if (bool.TryParse(value, out bool finalBook))
            {
                return(finalBook);
            }

            return(true);
        }
        public BookFlightDto GetBookFlightDto(List <int> id, string cabintype)
        {
            if (id.Count != 0)
            {
                decimal multiple = 1;
                switch (cabintype)
                {
                case "Business":
                    multiple = (decimal)1.35;
                    break;

                case "First class":
                    multiple = (decimal)1.755;
                    break;

                default:
                    multiple = 1;
                    break;
                }

                string        flightnumber  = "";
                decimal       price         = 0;
                int           first_id      = id[0];
                int           last_id       = id[id.Count - 1];
                BookFlightDto bookFlightDto = new BookFlightDto();
                bookFlightDto.ScheduleID = "";
                foreach (int i in id)
                {
                    flightnumber             += $"[{session3.Schedules.SingleOrDefault(s => s.ID == i).FlightNumber}] - ";
                    price                    += Math.Ceiling(session3.Schedules.SingleOrDefault(s => s.ID == i).EconomyPrice *multiple);
                    bookFlightDto.ScheduleID += $"{i},";
                }
                flightnumber                = flightnumber.Remove(flightnumber.Length - 3);
                bookFlightDto.ScheduleID    = bookFlightDto.ScheduleID.Remove(bookFlightDto.ScheduleID.Length - 2);
                bookFlightDto.From          = session3.Schedules.SingleOrDefault(s => s.ID == first_id).Route.Airport.IATACode;
                bookFlightDto.To            = session3.Schedules.SingleOrDefault(s => s.ID == last_id).Route.Airport1.IATACode;
                bookFlightDto.Date          = session3.Schedules.SingleOrDefault(s => s.ID == first_id).Date.ToString("dd/MM/yyyy");
                bookFlightDto.Time          = session3.Schedules.SingleOrDefault(s => s.ID == first_id).Time.ToString();
                bookFlightDto.FlightNumber  = flightnumber;
                bookFlightDto.CabinPrice    = price.ToString("C1", CultureInfo.CurrentCulture);
                bookFlightDto.NumberOfStops = id.Count - 1;

                return(bookFlightDto);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
        public async Task <bool> BookFlight(BookFlightDto bookFligth)
        {
            var reservarVuelo = new reservarVueloRequest(GetFlight(bookFligth.Flight), bookFligth.PassengerName, bookFligth.PassengerIdentification);

            try
            {
                var respuesta = await _flightService.reservarVueloAsync(reservarVuelo);

                return(respuesta.result);
            }
            catch (Exception)
            {
                throw new ProviderNotResponseException();
            }
        }
        public List <BookFlightDto> GetListBookFlightDto(List <List <int> > routevalues, string cabintype)
        {
            BookFlightDto temp = new BookFlightDto();

            try
            {
                List <BookFlightDto> result = new List <BookFlightDto>();
                foreach (List <int> routevalue in routevalues)
                {
                    result.Add(GetBookFlightDto(routevalue, cabintype));
                }
                return(result.OrderBy(r => r.Date).ToList());
            }
            catch (Exception)
            {
                return(null);
            }
        }