/// <summary> /// Method is called when customer registration is attempted /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event</param> private async void RegistrationCompleted(object sender, CustomerRegistrationCompletedEventArgs e) { if (Activity == null) { cachedAction = () => { RegistrationCompleted(sender, e); }; return; } await this.SaveCustomerToDevice(e); await this.MarkReadyForUpload(e); this.WizardActivity.HideWait(); if (e.Channel == DataChannel.Fallback) { this.RegistrationByFallbackCompleted(e); } else { this.RegistrationByDataCompleted(e); } this.CustomerService.RegistrationAttempted -= this.RegistrationAttempted; this.CustomerService.RegistrationCompleted -= this.RegistrationCompleted; }
private void RegistrationByFallbackCompleted(CustomerRegistrationCompletedEventArgs e) { string posButtonTxt = Activity.GetString(Resource.String.add_new_customer); string negButtonTxt = Activity.GetString(Resource.String.return_to_customer_details); string message = Activity.GetString(Resource.String.sms_registration_done); if (!e.Succeeded) { message = Activity.GetString(Resource.String.sms_registration_failed_three_tries); } Bundle arguments = new Bundle(); arguments.PutBoolean(RegistrationFinishedFragment.WasRegistrationKey, true); arguments.PutBoolean(RegistrationFinishedFragment.SuccessKey, e.Succeeded); arguments.PutString(RegistrationFinishedFragment.MessageKey, message); arguments.PutString(RegistrationFinishedFragment.BtnPositiveKey, posButtonTxt); arguments.PutString(RegistrationFinishedFragment.BtnNegativeKey, negButtonTxt); int maxFallbackTries = Settings.Instance.MaxFallbackRetries; arguments.PutInt(RegistrationFinishedFragment.Retries, maxFallbackTries); ShowRegistrationStatus(arguments); if (e.Succeeded) { AlertDialog.Dismiss(); _customerSearchResult.SyncStatus = RecordStatus.FallbackSent; new CustomersController().SaveCustomerToDevice(_customer, e, false); UpdateUi(true); } }
private void FireRegistrationCompleted(CustomerRegistrationCompletedEventArgs e) { if (this.RegistrationCompleted != null) { this.RegistrationCompleted(this, e); } }
private async Task MarkReadyForUpload(CustomerRegistrationCompletedEventArgs e) { if (e == null || !e.Succeeded) { return; } CustomerPhotoService service = new CustomerPhotoService(); await service.MarkForUpload(this.personRegistrationInfo.NationalId); }
private void RegistrationByDataCompleted(CustomerRegistrationCompletedEventArgs e) { this._registrationFinishedOverlay = new RegistrationFinishedFragment(); Bundle arguments = new Bundle(); arguments.PutBoolean(RegistrationFinishedFragment.WasRegistrationKey, false); arguments.PutBoolean(RegistrationFinishedFragment.SuccessKey, e.Succeeded); arguments.PutString(RegistrationFinishedFragment.IntentStartPointKey, this.ActivityBase.StartPointIntent.ToString()); arguments.PutString(RegistrationFinishedFragment.BtnNegativeKey, this.OverlayNegativeButtonText); this._registrationFinishedOverlay.Arguments = arguments; this.WizardActivity.ShowOverlay(this._registrationFinishedOverlay, true); }
/// <summary> /// Method is called when customer registration is attempted /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event</param> private async void RegistrationCompleted(object sender, CustomerRegistrationCompletedEventArgs e) { if (Activity == null) { return; } if (e.Channel == DataChannel.Fallback) { this.RegistrationByFallbackCompleted(e); } else { this.RegistrationByDataCompleted(e); } }
private void RegistrationByDataCompleted(CustomerRegistrationCompletedEventArgs e) { Bundle arguments = new Bundle(); arguments.PutBoolean(RegistrationFinishedFragment.WasRegistrationKey, false); arguments.PutBoolean(RegistrationFinishedFragment.SuccessKey, e.Succeeded); arguments.PutString(RegistrationFinishedFragment.MessageKey, Activity.GetString(Resource.String.successful_registration_message)); ShowRegistrationStatus(arguments); if (e.Succeeded) { AlertDialog.Dismiss(); _customerSearchResult.SyncStatus = RecordStatus.Synced; _customerSearchResult.Channel = DataChannel.Full; new CustomersController().SaveCustomerToDevice(_customer, e, false); UpdateUi(true); } }
/// <summary> /// Called to save a customer to the device /// </summary> /// <returns>An empty task</returns> private async Task SaveCustomerToDevice(CustomerRegistrationCompletedEventArgs e) { if (e == null) { return; } this.personRegistrationInfo.Channel = e.Channel; //if we have a successfully generated customer registration Id from the API, set the corresponding property in the Customer Model if (e.RegistrationId != Guid.Empty) { this.personRegistrationInfo.RegistrationId = e.RegistrationId; } try { SalesApp.Core.BL.Models.People.Customer customer = await new CustomersController().SaveCustomerToDevice(this.personRegistrationInfo, e, false); if (customer == null || customer.Id == default(Guid)) { new ReusableScreens(this.Activity) .ShowInfo( Resource.String.customer_save_err_actionbar, Resource.String.customer_save_err_title, Resource.String.customer_save_err_message, Resource.String.customer_save_err_button); } } catch (DuplicateValuesException dx) { new ReusableScreens(this.Activity) .ShowInfo( Resource.String.customer_save_err_actionbar, Resource.String.customer_save_err_title, Resource.String.customer_duplicate_error_message, Resource.String.customer_save_err_button); } }
private void RegistrationByFallbackCompleted(CustomerRegistrationCompletedEventArgs e) { string posButtonTxt = this.WizardActivity.GetString(Resource.String.add_new_customer); this._registrationFinishedOverlay = new RegistrationFinishedFragment(); string message = string.Format(this.WizardActivity.GetString(Resource.String.unified_sms_registration_failed_n_tries), 3); Bundle arguments = new Bundle(); arguments.PutBoolean(RegistrationFinishedFragment.WasRegistrationKey, true); arguments.PutBoolean(RegistrationFinishedFragment.SuccessKey, e.Succeeded); arguments.PutString(RegistrationFinishedFragment.MessageKey, message); arguments.PutString(RegistrationFinishedFragment.BtnPositiveKey, posButtonTxt); arguments.PutString(RegistrationFinishedFragment.BtnNegativeKey, this.OverlayNegativeButtonText); arguments.PutString(RegistrationFinishedFragment.IntentStartPointKey, this.ActivityBase.StartPointIntent.ToString()); int maxFallbackTries = Settings.Instance.MaxFallbackRetries; arguments.PutInt(RegistrationFinishedFragment.Retries, maxFallbackTries); this._registrationFinishedOverlay.Arguments = arguments; this.WizardActivity.ShowOverlay(this._registrationFinishedOverlay, true); }
public async Task <Customer> SaveCustomerToDevice( Customer personRegistrationInfo, CustomerRegistrationCompletedEventArgs e, bool b) { ProspectsController prospectsController = new ProspectsController(); try { Prospect prospect = await prospectsController .GetByPhoneNumberAsync(personRegistrationInfo.Phone, false); this.Logger.Debug("Trying to save customer"); // check whether the customer is on the device, if not save the customer Customer existingCustomer = await this.GetSingleRecord(new CriteriaBuilder().Add("Phone", personRegistrationInfo.Phone)); if (existingCustomer != null) { personRegistrationInfo.Id = existingCustomer.Id; } await DataAccess.Instance.Connection.RunInTransactionAsync( async connTran => { DataAccess.Instance.StartTransaction(connTran); await this.SaveAsync(connTran, personRegistrationInfo); if (personRegistrationInfo.Id != default(Guid)) { await new CustomerProductController().SaveCustomerProductToDevice( connTran, personRegistrationInfo.Id, personRegistrationInfo.Product); if (prospect != null) { this.Logger.Debug("There was a prospect with the same number so we convert to customer"); prospect.Converted = true; await prospectsController.SaveAsync(connTran, prospect); } RecordStatus syncStatus = RecordStatus.Synced; if (personRegistrationInfo.Channel == DataChannel.Fallback) { if (e.Succeeded) { syncStatus = RecordStatus.FallbackSent; this.Logger.Debug("Status = " + syncStatus); } else { syncStatus = RecordStatus.Pending; this.Logger.Debug("Status = " + syncStatus); } } SyncingController syncController = new SyncingController(); SyncRecord syncRec = await syncController.GetSyncRecordAsync(personRegistrationInfo.RequestId); this.Logger.Debug("Fetching sync record for customer"); if (syncRec == null) { this.Logger.Debug("The sync record is null so we generate one"); syncRec = new SyncRecord { ModelId = personRegistrationInfo.Id, ModelType = personRegistrationInfo.TableName, Status = syncStatus, RequestId = personRegistrationInfo.RequestId }; } else { syncRec.Status = syncStatus; } await syncController.SaveAsync(connTran, syncRec); } }); DataAccess.Instance.CommitTransaction(); return(personRegistrationInfo); } catch (DuplicateValuesException ex) { throw new DuplicateValuesException(ex.FieldName, ex.Value, ex.Count); } catch (Exception exception) { this.Logger.Error(exception); return(null); } }
private async Task <bool> AttemptDataRegistration(BL.Models.People.Customer customer) { if (!Resolver.Instance.Get <IConnectivityService>().HasConnection()) { return(false); } // try to post the person via the API, for configurable x tries CustomerRegistrationResponse response = null; int apiTries = 1; while (apiTries <= this.numberOfRetries) { Log.Verbose("API register try " + apiTries); // call the API and await response response = await this.RegisterViaApi(customer); response.Customer = customer; if (response.Successful) { this.RegistrationSuccessful = true; if (response.RegistrationId != Guid.Empty) { var registrationCompletedEventArgs = new CustomerRegistrationCompletedEventArgs( DataChannel.Full, true) { RegistrationId = response.RegistrationId }; this.FireRegistrationCompleted(registrationCompletedEventArgs); } else { this.FireRegistrationCompleted(DataChannel.Full, true); } return(true); } this.FireRegistrationAttempted(DataChannel.Full, apiTries); // exception on reported 500 error, do not continue if (response.ResponseText.Equals("HttpResponse500Exception")) { Log.Error("API threw 500 error (HttpResponse500Exception)."); break; } // next retry apiTries++; } // make sure the warning logging never fails, it is extra information try { var responseText = response == null ? "response=null" : response.ResponseText; Log.Warning("Fallback Registration: Attempts to register via Internet failed. ResponseText = " + responseText); } catch (Exception e) { Log.Error(e); } return(false); }