public object Get(FindMarketRequest request) { var market = _taxiHailNetworkServiceClient.GetCompanyMarket(request.Latitude, request.Longitude); // Hash market so that client doesn't have direct access to its value return(_cryptographyService.GetHashString(market)); }
public AvailableVehiclesResponse Post(AvailableVehicles request) { var vehicleType = _dao.GetAll().FirstOrDefault(v => v.ReferenceDataVehicleId == request.VehicleTypeId); var logoName = vehicleType != null ? vehicleType.LogoName : null; IbsVehiclePosition[] ibsVehicles; string market = null; try { market = _taxiHailNetworkServiceClient.GetCompanyMarket(request.Latitude, request.Longitude); } catch { // Do nothing. If we fail to contact Customer Portal, we continue as if we are in a local market. _logger.LogMessage("VehicleService: Error while trying to get company Market to find available vehicles."); } if (!market.HasValue() && _serverSettings.ServerData.LocalAvailableVehiclesMode == LocalAvailableVehiclesModes.IBS) { // LOCAL market IBS ibsVehicles = _ibsServiceProvider.Booking().GetAvailableVehicles(request.Latitude, request.Longitude, request.VehicleTypeId); } else { string availableVehiclesMarket; IList <int> availableVehiclesFleetIds = null; if (!market.HasValue() && _serverSettings.ServerData.LocalAvailableVehiclesMode == LocalAvailableVehiclesModes.HoneyBadger) { // LOCAL market Honey Badger availableVehiclesMarket = _serverSettings.ServerData.HoneyBadger.AvailableVehiclesMarket; if (request.FleetIds != null) { // Use fleet ids specified in the request first availableVehiclesFleetIds = request.FleetIds; } else if (_serverSettings.ServerData.HoneyBadger.AvailableVehiclesFleetId.HasValue) { // Or fleet id specified in the settings availableVehiclesFleetIds = new[] { _serverSettings.ServerData.HoneyBadger.AvailableVehiclesFleetId.Value }; } } else if (!market.HasValue() && _serverSettings.ServerData.LocalAvailableVehiclesMode == LocalAvailableVehiclesModes.Geo) { // LOCAL market Geo availableVehiclesMarket = _serverSettings.ServerData.CmtGeo.AvailableVehiclesMarket; if (_serverSettings.ServerData.CmtGeo.AvailableVehiclesFleetId.HasValue) { availableVehiclesFleetIds = new[] { _serverSettings.ServerData.CmtGeo.AvailableVehiclesFleetId.Value }; } } else { // EXTERNAL market Honey Badger or Geo availableVehiclesMarket = market; try { // Only get available vehicles for dispatchable companies in market var roamingCompanies = _taxiHailNetworkServiceClient.GetMarketFleets(_serverSettings.ServerData.TaxiHail.ApplicationKey, market); if (roamingCompanies != null) { var roamingFleetIds = roamingCompanies.Select(r => r.FleetId); if (request.FleetIds != null) { // From the fleets accessible by that company, only return vehicles from the fleets specified in the request availableVehiclesFleetIds = roamingFleetIds .Where(fleetId => request.FleetIds.Contains(fleetId)) .ToArray(); } else { // Return vehicles from all fleets accessible by that company availableVehiclesFleetIds = roamingFleetIds.ToArray(); } } else { availableVehiclesFleetIds = request.FleetIds; } } catch { // Do nothing. If we fail to contact Customer Portal, we return an unfiltered list of available vehicles. _logger.LogMessage("VehicleService: Error while trying to get Market fleets."); } } var vehicleResponse = GetAvailableVehiclesServiceClient(market).GetAvailableVehicles( market: availableVehiclesMarket, latitude: request.Latitude, longitude: request.Longitude, searchRadius: request.SearchRadius, fleetIds: availableVehiclesFleetIds, wheelchairAccessibleOnly: (vehicleType != null && vehicleType.IsWheelchairAccessible)); ibsVehicles = vehicleResponse.Select(v => new IbsVehiclePosition { Latitude = v.Latitude, Longitude = v.Longitude, PositionDate = v.Timestamp, VehicleNumber = v.Medallion, FleetId = v.FleetId, Eta = (int?)v.Eta, VehicleType = v.VehicleType, CompassCourse = v.CompassCourse, }).ToArray(); } var isAuthenticated = this.GetSession().IsAuthenticated; var availableVehicles = new List <AvailableVehicle>(); foreach (var ibsVehicle in ibsVehicles) { var vehicle = new AvailableVehicle { Latitude = ibsVehicle.Latitude, Longitude = ibsVehicle.Longitude, LogoName = logoName, Eta = ibsVehicle.Eta, VehicleType = ibsVehicle.VehicleType }; if (isAuthenticated) { vehicle.CompassCourse = ibsVehicle.CompassCourse ?? 0; vehicle.VehicleName = ibsVehicle.VehicleNumber; vehicle.FleetId = ibsVehicle.FleetId; } availableVehicles.Add(vehicle); } return(new AvailableVehiclesResponse(availableVehicles)); }
public object Post(SwitchOrderToNextDispatchCompanyRequest request) { _logger.LogMessage("Switching order to another IBS : " + request.ToJson()); var account = _accountDao.FindById(new Guid(this.GetSession().UserAuthId)); var order = _orderDao.FindById(request.OrderId); var orderStatusDetail = _orderDao.FindOrderStatusById(request.OrderId); if (orderStatusDetail.Status != OrderStatus.TimedOut) { // Only switch companies if order is timedout return(orderStatusDetail); } // We are in a network timeout situation. if (orderStatusDetail.CompanyKey == request.NextDispatchCompanyKey) { _ibsCreateOrderService.CancelIbsOrder(order.IBSOrderId, order.CompanyKey, order.Settings.Phone, account.Id); orderStatusDetail.IBSStatusId = VehicleStatuses.Common.Timeout; orderStatusDetail.IBSStatusDescription = _resources.Get("OrderStatus_" + VehicleStatuses.Common.Timeout); return(orderStatusDetail); } var market = _taxiHailNetworkServiceClient.GetCompanyMarket(order.PickupAddress.Latitude, order.PickupAddress.Longitude); var isConfiguredForCmtPayment = _taxiHailNetworkHelper.FetchCompanyPaymentSettings(request.NextDispatchCompanyKey); var chargeTypeId = order.Settings.ChargeTypeId; var chargeTypeDisplay = order.Settings.ChargeType; if (!isConfiguredForCmtPayment) { // Only companies configured for CMT payment can support CoF orders outside of home market chargeTypeId = ChargeTypes.PaymentInCar.Id; chargeTypeDisplay = ChargeTypes.PaymentInCar.Display; } var newOrderRequest = new CreateOrderRequest { PickupDate = GetCurrentOffsetedTime(request.NextDispatchCompanyKey), PickupAddress = order.PickupAddress, DropOffAddress = order.DropOffAddress, Settings = new BookingSettings { LargeBags = order.Settings.LargeBags, Name = order.Settings.Name, NumberOfTaxi = order.Settings.NumberOfTaxi, Passengers = order.Settings.Passengers, Phone = order.Settings.Phone, ProviderId = null, ChargeType = chargeTypeDisplay, ChargeTypeId = chargeTypeId, // Reset vehicle type VehicleType = null, VehicleTypeId = null }, Note = order.UserNote, ClientLanguageCode = account.Language }; var fare = FareHelper.GetFareFromEstimate(new RideEstimate { Price = order.EstimatedFare }); var newReferenceData = (ReferenceData)_referenceDataService.Get(new ReferenceDataRequest { CompanyKey = request.NextDispatchCompanyKey }); // This must be localized with the priceformat to be localized in the language of the company // because it is sent to the driver var chargeTypeIbs = _resources.Get(chargeTypeDisplay, _serverSettings.ServerData.PriceFormat); var ibsInformationNote = IbsHelper.BuildNote( _serverSettings.ServerData.IBS.NoteTemplate, chargeTypeIbs, order.UserNote, order.PickupAddress.BuildingName, newOrderRequest.Settings.LargeBags, _serverSettings.ServerData.IBS.HideChargeTypeInUserNote); var networkErrorMessage = string.Format(_resources.Get("Network_CannotCreateOrder", order.ClientLanguageCode), request.NextDispatchCompanyName); int ibsAccountId; try { // Recreate order on next dispatch company IBS ibsAccountId = CreateIbsAccountIfNeeded(account, request.NextDispatchCompanyKey); } catch (Exception ex) { _logger.LogMessage(networkErrorMessage); _logger.LogError(ex); throw new HttpError(HttpStatusCode.InternalServerError, networkErrorMessage); } ValidateProvider(newOrderRequest, newReferenceData, market.HasValue(), null); var newOrderCommand = Mapper.Map <CreateOrder>(newOrderRequest); newOrderCommand.OrderId = request.OrderId; newOrderCommand.ReferenceDataCompanyList = newReferenceData.CompaniesList.ToArray(); newOrderCommand.Market = market; newOrderCommand.CompanyKey = request.NextDispatchCompanyKey; newOrderCommand.CompanyName = request.NextDispatchCompanyName; newOrderCommand.Fare = fare; newOrderCommand.IbsInformationNote = ibsInformationNote; _commandBus.Send(new InitiateIbsOrderSwitch { NewIbsAccountId = ibsAccountId, NewOrderCommand = newOrderCommand }); return(new OrderStatusDetail { OrderId = request.OrderId, Status = OrderStatus.Created, CompanyKey = request.NextDispatchCompanyKey, CompanyName = request.NextDispatchCompanyName, NextDispatchCompanyKey = null, NextDispatchCompanyName = null, IBSStatusId = string.Empty, IBSStatusDescription = string.Format(_resources.Get("OrderStatus_wosWAITINGRoaming", order.ClientLanguageCode), request.NextDispatchCompanyName), }); }