Пример #1
0
        public object Post(HailRequest request)
        {
            _logger.LogMessage(string.Format("Starting Hail. Request : {0}", request.ToJson()));

            var createOrderRequest = Mapper.Map <CreateOrderRequest>(request);

            var account           = _accountDao.FindById(new Guid(this.GetSession().UserAuthId));
            var createReportOrder = CreateReportOrder(createOrderRequest, account);

            var createOrderCommand = BuildCreateOrderCommand(createOrderRequest, account, createReportOrder);

            var result = _ibsCreateOrderService.CreateIbsOrder(createOrderCommand.OrderId, createOrderCommand.PickupAddress,
                                                               createOrderCommand.DropOffAddress, createOrderCommand.Settings.AccountNumber, createOrderCommand.Settings.CustomerNumber,
                                                               createOrderCommand.CompanyKey, createOrderCommand.IbsAccountId, createOrderCommand.Settings.Name, createOrderCommand.Settings.Phone, account.Email,
                                                               createOrderCommand.Settings.Passengers, createOrderCommand.Settings.VehicleTypeId, createOrderCommand.IbsInformationNote, createOrderCommand.IsFutureBooking,
                                                               createOrderCommand.PickupDate, createOrderCommand.Prompts, createOrderCommand.PromptsLength, createOrderCommand.ReferenceDataCompanyList,
                                                               createOrderCommand.Market, createOrderCommand.Settings.ChargeTypeId, createOrderCommand.Settings.ProviderId, createOrderCommand.Fare,
                                                               createOrderCommand.TipIncentive, account.DefaultTipPercent, createOrderCommand.AssignVehicleId, true, createOrderCommand.CompanyFleetId);

            if (result.HailResult.OrderKey.IbsOrderId > -1)
            {
                createOrderCommand.IbsOrderId = result.HailResult.OrderKey.IbsOrderId;

                _commandBus.Send(createOrderCommand);
            }

            return(result.HailResult);
        }
        public void Handle(OrderCreated @event)
        {
            // Normal order flow
            _logger.LogMessage(string.Format("OrderCreationManager::Handle(OrderCreated) ibsOrder: {0}", @event.IBSOrderId));

            var isPaypalPrepaid = @event.IsPrepaid &&
                                  @event.Settings.ChargeTypeId == ChargeTypes.PayPal.Id;

            if (isPaypalPrepaid)
            {
                // Paypal orders are handled in their own methods
                return;
            }

            var ibsOrderId = @event.IBSOrderId;
            var account    = _accountDao.FindById(@event.AccountId);

            if (!ibsOrderId.HasValue)
            {
                // If order wasn't already created on IBS (which should be most of the time), we create it here
                var result = _ibsCreateOrderService.CreateIbsOrder(@event.SourceId, @event.PickupAddress, @event.DropOffAddress, @event.Settings.AccountNumber,
                                                                   @event.Settings.CustomerNumber, @event.CompanyKey, @event.IbsAccountId,
                                                                   @event.Settings.Name, @event.Settings.Phone, account.Email, @event.Settings.Passengers, @event.Settings.VehicleTypeId,
                                                                   @event.IbsInformationNote, @event.IsFutureBooking, @event.PickupDate, @event.Prompts, @event.PromptsLength,
                                                                   @event.ReferenceDataCompanyList.ToList(), @event.Market, @event.Settings.ChargeTypeId, @event.Settings.ProviderId, @event.Fare,
                                                                   @event.TipIncentive, account.DefaultTipPercent, @event.AssignVehicleId);

                ibsOrderId = result.CreateOrderResult;
            }

            var success = SendOrderCreationCommands(@event.SourceId, ibsOrderId, @event.IsPrepaid, @event.ClientLanguageCode);

            if (success)
            {
                SendConfirmationEmail(ibsOrderId.Value, @event.AccountId, @event.Settings, @event.ChargeTypeEmail,
                                      @event.PickupAddress, @event.DropOffAddress, @event.PickupDate, @event.UserNote, @event.ClientLanguageCode);

                ApplyPromotionIfNecessary(@event);
            }

            _ibsCreateOrderService.UpdateOrderStatusAsync(@event.SourceId);
        }