Example #1
0
      private GetSubscriberInfoResult _getCustomer(A.GetContactRelatedInfoResponse res) {
         if (res == null || res.person == null || res.person.personDetails == null) return null;
         var details = res.person.personDetails;

         var opco = _getOperator(details.IMTSI);
         if (opco == null) return null;

         var driver = new DriverInfo {
            DriverId = BplIdentity.Get(details.IMTSI),
            DriverSsn = details.personID,
            Operator = opco,
            Gender = _getGender(details.gender),
            Type = DriverTypes.Subscriber
         };

         var subscriber = new GetSubscriberInfoResult {
            DriverInfo = driver
         };

         var lang = opco.DefaultLanguage;
         if (lang.NotEmpty()) {
            driver.DefaultLocale = new Locale(lang);
            driver.Name = _getMultiString("{0} {1}".Substitute(details.firstName, details.lastName), lang);
         }
         
         if (details.birthdateSpecified) {
            driver.BirthDate = (Date)details.birthdate;
         }

         if (details.primaryAddress != null) {
            var addr = _getAddress(details.primaryAddress, opco, ContactTypes.HomeAddress);
            if (addr != null) {
               driver.Contacts.Add(addr);
            }
         }

         if (details.additionalAddresses != null) {
            foreach (var a in details.additionalAddresses) {
               var addr = _getAddress(a, opco, ContactTypes.OtherAddress);
               if (addr != null) {
                  driver.Contacts.Add(addr);
               }
            }
         }

         if (details.email != null) {
            driver.Contacts.Add(new Contact { Type = ContactTypes.Email, Value = details.email });
         }

         if (details.contactMethodInfo != null) {
            driver.Contacts.AddRange(details.contactMethodInfo.Select(c => _getContactInfo(c, opco)));
         }

         if (details.invoiceIndicator != null) {
            driver.Type = (bool)details.invoiceIndicator ? DriverTypes.Payer : DriverTypes.Subscriber;
         }

         if (res.vehicleList != null) {
            for (int i = 0; i < res.vehicleList.Length; i++) {
               subscriber.DriverVehicles.Add(new VehicleInfo {
                  LicensePlate = res.vehicleList[i].licensePlate,
                  VehicleId = BplIdentity.Get(res.vehicleList[i].vehicleID)
               });
            }
         }

         return subscriber;
      }
Example #2
0
      private void _onSuccess(GetSubscriberInfoResult o) {
         if (o == null) {
            Log.Warn("Empty reply recieved for GetDriverInfo.");
            Reply(null);
            return;
         }

         var result = o.DriverInfo;
         Log.Trace("Add driver {0} to DB", result.DriverId);

         using (var dbConn = DatabaseManager.DbConn()) {
            var di = o.DriverInfo;
            if (di.DataSource == null) {
               Log.Warn("Driver datasource is NULL, cloning and setting 'Backend'");
               di = o.DriverInfo.Clone<DriverInfo>();
               di.DataSource = DataSources.Backend;
            }

            var exDriver = dbConn.ExecuteBpl(new DriverGetById { DriverId = di.DriverId });
            if (exDriver != null) {
               if ((exDriver.DataSource == DataSources.Backend) || (OscarServer.UseBackendMasterData)) {

                  // TK: we are using OpCo settings from SD (periodic)
                  di.Operator = exDriver.Operator;

                  dbConn.ExecuteBpl(new DriverUpdate { i = di });
               }
            } else {
               dbConn.ExecuteBpl(new DriverAdd { i = di });
            }

            if ((exDriver == null) ||
               ((exDriver.DataSource == DataSources.Backend) || (OscarServer.UseBackendMasterData))) {
               dbConn.ExecuteBpl(new ContactRemoveById { ContactId = o.DriverInfo.DriverId });
               foreach (var ct in o.DriverInfo.Contacts) {
                  if (ct.Value.IsEmpty() == true) {
                     continue;
                  }

                  var ci = new ContactInfo();
                  ci.ContactId = o.DriverInfo.DriverId;
                  ci.Type = ct.Type;
                  ci.Value = ct.Value;

                  dbConn.ExecuteBpl(new ContactAdd { i = ci });
               }

               dbConn.ExecuteBpl(new SubscriptionDeleteByDriverId { DriverId = o.DriverInfo.DriverId });

               if (o.DriverVehicles != null) {
                  foreach (var vh in o.DriverVehicles) {
                     var dbvi = BackendHelpers.VehicleSave(dbConn, vh);

                     if (dbvi != null) {
                        var subi = new DbSubscriptionInfo();

                        subi.SubscriptionInfo.SubscriptionId = BplIdentity.Get(Guid.NewGuid().ToString());
                        subi.SubscriptionInfo.Operator = dbvi.VehicleInfo.Operator;
                        subi.SubscriptionInfo.Type = SubscriptionType.Get("EV");
                        subi.SubscriptionInfo.Status = SubscriptionStatus.Active;
                        subi.SubscriptionInfo.DriverId = o.DriverInfo.DriverId;
                        subi.SubscriptionInfo.DataSource = DataSources.Backend;
                        subi.VehicleKey = dbvi.VehicleKey;

                        dbConn.ExecuteBpl(new SubscriptionAdd { i = subi });
                     }
                  }
               }
            }
         }

         if (_isReplyRequired) {
            Log.Trace("Reply to node with DriverInfo {0}", result);
            Reply(result);
         }
      }