public async Task <JsonResult> GetItinerariesByTripDescription(CreateSessionViewModel viewModel) { // Check defaults if (viewModel.Locale == null) { viewModel.Locale = "en-US"; } if (viewModel.Country == null) { viewModel.Country = "US"; } if (viewModel.Currency == null) { viewModel.Currency = "USD"; } DateTime parsedOutboundDate; try { parsedOutboundDate = DateTime.Parse(viewModel.OutboundDate); } catch { parsedOutboundDate = DateTime.Now.AddMonths(1); } DateTime parsedInboundDate; try { parsedInboundDate = DateTime.Parse(viewModel.InboundDate); } catch { parsedInboundDate = DateTime.Now.AddMonths(2); } viewModel.OutboundDate = parsedOutboundDate.ToString("yyyy-MM-dd"); viewModel.InboundDate = parsedInboundDate.ToString("yyyy-MM-dd"); if (User.Identity.IsAuthenticated) { var id = User.Identity.GetUserId(); HistoryService.AddHistoryRecord(viewModel, id); } /* * // Create a session with ScyScanner * * var subUrl = $"pricing/v1.0"; * * var content = ToUrlEncodedContent(viewModel); * * string userApi = Request.UserHostAddress; * string bodyString = $"cabinclass={viewModel.CabinClass}&country={viewModel.Country}¤cy={viewModel.Currency}&locale={viewModel.Locale}&locationSchema=iata&originplace={viewModel.OriginPlace}&destinationplace={viewModel.DestinationPlace}&outbounddate={viewModel.OutboundDate}&inbounddate={viewModel.InboundDate}&adults={viewModel.Adults}&children={viewModel.Children}&infants={viewModel.Infants}"; * string locationHeader = await _searchService.GetLocationHeader(subUrl, content, bodyString, userApi); */ var partialUrl = string.Format(CultureInfo.CurrentCulture, $"browseroutes/v1.0/{viewModel.Country}/{viewModel.Currency}/{viewModel.Locale}/{viewModel.OriginPlace}/{viewModel.DestinationPlace}/{viewModel.OutboundDate}/{viewModel.InboundDate}?"); var routes = await _searchService.GetFromUrl <RoutesWrapper>(partialUrl); // It's a terrible hack to simplify data manipulation on the frontend IEnumerable <QuoteExpanded> quotesExpanded = routes.Quotes.Select(quote => new QuoteExpanded() { QuoteId = quote.QuoteId, MinPrice = string.Format(CultureInfo.CurrentCulture, "{0} {1}", quote.MinPrice, routes.Currencies.FirstOrDefault().Symbol), MinPriceNum = quote.MinPrice, Direct = quote.Direct, QuoteDateTime = quote.QuoteDateTime, OutboundLeg = quote.OutboundLeg == null ? null : new OutboundlegExpanded() { DepartureDate = quote.OutboundLeg.DepartureDate, Destination = routes.Places.SingleOrDefault(place => quote.OutboundLeg.DestinationId == place.PlaceId), Origin = routes.Places.SingleOrDefault(place => quote.OutboundLeg.OriginId == place.PlaceId), Carriers = routes.Carriers.Where(carrier => quote.OutboundLeg.CarrierIds.Contains(carrier.CarrierId)).ToArray() }, InboundLeg = quote.InboundLeg == null ? null : new InboundlegExpanded() { DepartureDate = quote.InboundLeg.DepartureDate, Destination = routes.Places.SingleOrDefault(place => quote.InboundLeg.DestinationId == place.PlaceId), Origin = routes.Places.SingleOrDefault(place => quote.InboundLeg.OriginId == place.PlaceId), Carriers = routes.Carriers.Where(carrier => quote.InboundLeg.CarrierIds.Contains(carrier.CarrierId)).ToArray() } }).Take(50); var json = Json(quotesExpanded, JsonRequestBehavior.AllowGet); Thread.Sleep(1000); return(json); }