Exemple #1
0
        public async void Handle(OrderTimedOut @event)
        {
            using (var context = _contextFactory.Invoke())
            {
                var details = context.Find <OrderStatusDetail>(@event.SourceId);
                if (details == null)
                {
                    throw new InvalidOperationException("Order Status not found");
                }

                var order = context.Find <OrderDetail>(@event.SourceId);
                if (order == null)
                {
                    throw new InvalidOperationException("Order not found");
                }

                var pickUpPosition = new MapCoordinate
                {
                    Latitude  = order.PickupAddress.Latitude,
                    Longitude = order.PickupAddress.Longitude
                };

                NetworkFleetResponse nextDispatchCompany = null;

                if (@event.Market.HasValue())
                {
                    // External market
                    var marketFleet = GetMarketFleets(@event.Market, details.CompanyKey, pickUpPosition.Latitude, pickUpPosition.Longitude);
                    nextDispatchCompany = FindNextDispatchCompany(details.CompanyKey, pickUpPosition, marketFleet, @event.Market);
                }
                else
                {
                    // Local market
                    var taxiHailNetworkSettings = _configurationDao.GetUserTaxiHailNetworkSettings(details.AccountId)
                                                  ?? new UserTaxiHailNetworkSettings {
                        IsEnabled = true, DisabledFleets = new string[] {}
                    };

                    if (taxiHailNetworkSettings.IsEnabled)
                    {
                        var networkFleet = await _taxiHailNetworkServiceClient.GetNetworkFleetAsync(details.CompanyKey, pickUpPosition.Latitude, pickUpPosition.Longitude);

                        // Remove fleets that were disabled by the user
                        var userNetworkFleet = FilterNetworkFleet(taxiHailNetworkSettings.DisabledFleets, networkFleet);

                        nextDispatchCompany = FindNextDispatchCompany(details.CompanyKey, pickUpPosition, userNetworkFleet);
                    }
                }

                if (nextDispatchCompany != null)
                {
                    _commandBus.Send(new PrepareOrderForNextDispatch
                    {
                        OrderId             = details.OrderId,
                        DispatchCompanyName = nextDispatchCompany.CompanyName,
                        DispatchCompanyKey  = nextDispatchCompany.CompanyKey
                    });
                }
            }
        }
Exemple #2
0
        public object Get(UserTaxiHailNetworkSettingsRequest request)
        {
            if (request.AccountId == null)
            {
                return(new HttpError(HttpStatusCode.BadRequest, "Account Id cannot be null"));
            }

            var networkSettings = _configDao.GetUserTaxiHailNetworkSettings(request.AccountId.Value)
                                  ?? new UserTaxiHailNetworkSettings {
                IsEnabled = true, DisabledFleets = new string[] {}
            };

            return(new UserTaxiHailNetworkSettings
            {
                Id = networkSettings.Id,
                IsEnabled = networkSettings.IsEnabled,
                DisabledFleets = networkSettings.DisabledFleets
            });
        }