public object Post(FlightInformationRequest request)
		{
			var direction = request.IsPickup
				? "arr"
				: "dep";

			var endpoint = string.Format(
				StatusEndPoint, 
				request.CarrierCode, 
				request.FlightNumber, 
				direction, 
				request.Date.Year,
				request.Date.Month, 
				request.Date.Day,
				_serverSettings.ServerData.FlightStats.AppId,
				_serverSettings.ServerData.FlightStats.ApplicationKeys,
				request.AirportId
			);

			var flightStatsResponse = _client.GetAsync(endpoint)
				.Deserialize<FlightStatsResponse>()
				.Result;

			if (flightStatsResponse == null)
			{
				throw new HttpError(HttpStatusCode.NotFound, "No flight found.");
			}

			var error = flightStatsResponse.Error;

			if (error != null)
			{
				throw new HttpError(HttpStatusCode.BadRequest, "OrderAirportView_" + error.ErrorCode);
			}

			if (flightStatsResponse.FlightStatuses == null ||  flightStatsResponse.FlightStatuses.None())
			{
				throw new HttpError(HttpStatusCode.NotFound, "No flight found.");
			}

			var terminal = GetTerminal(flightStatsResponse.FlightStatuses, request.IsPickup, request.AirportId);

			if (!terminal.HasValue())
			{
				throw new HttpError(HttpStatusCode.NoContent,"No terminal found.");
			}

			return new FlightInformation
			{
				Terminal = terminal
			};
		}
示例#2
0
 public Task <FlightInformation> GetTerminal(FlightInformationRequest request)
 {
     return(Client.PostAsync(request, Logger));
 }
示例#3
0
        public async Task <string> GetTerminal(DateTime date, string flightNumber, string carrierCode, string carrierName, string airportId, bool isPickup)
        {
            var sanitizedCarrierCode = carrierCode.Contains(".")
                                ? carrierCode.Split('.')[1]
                                : carrierCode;

            var flightInformationRequest = new FlightInformationRequest
            {
                AirportId    = airportId,
                CarrierCode  = sanitizedCarrierCode.ToLowerInvariant(),
                Date         = date,
                FlightNumber = flightNumber,
                IsPickup     = isPickup
            };

            try
            {
                var airportInfo = await UseServiceClientAsync <FlightInformationServiceClient, FlightInformation>(service =>
                                                                                                                  service.GetTerminal(flightInformationRequest)
                                                                                                                  );

                return(airportInfo == null
                                        ? null
                                        : airportInfo.Terminal);
            }
            catch (WebServiceException ex)
            {
                var showMessage = false;

                if (ex.StatusCode == (int)HttpStatusCode.NoContent)
                {
                    return(NotAvailable);
                }

                if (ex.StatusCode == (int)HttpStatusCode.BadRequest)
                {
                    _messageService
                    .ShowMessage(_localizeService["Error"], string.Format(_localizeService[ex.ErrorCode], carrierName, flightNumber, date.ToString("g")))
                    .FireAndForget();

                    return(string.Empty);
                }

                if (ex.StatusCode == (int)HttpStatusCode.NotFound)
                {
                    showMessage = true;
                }

                Logger.LogMessage("An error has occurred while attempting to get the airport terminal.");
                Logger.LogError(ex);

                if (!showMessage)
                {
                    return(string.Empty);
                }
            }

            var cancel = false;

            await _messageService.ShowMessage(
                _localizeService["BookingAirportNoFlights_Title"],
                string.Format(_localizeService["BookingAirportNoFlights_Message"], carrierName, flightNumber, date.ToString("g")),
                _localizeService["YesButton"],
                () => { },
                _localizeService["NoButton"],
                () => cancel = true);


            return(cancel
                                ? string.Empty
                                : NotAvailable);
        }