Пример #1
0
        private async Task <RegistrationStatusOverview> GetOverViewAsync(List <CustomerRegistrationStepsStatus> statusList)
        {
            RegistrationStatusOverview overview = new RegistrationStatusOverview();

            if (statusList == null || statusList.Count == 0)
            {
                return(null);
            }

            // order the list to make sure we have the right order in steps
            statusList = statusList.OrderBy(l => l.StepNumber).ToList();

            // set the total amount of steps
            overview.TotalSteps = statusList.Count;

            // scan list and find the right steps for the overview
            foreach (var status in statusList)
            {
                if (status.StepName == Rejected)
                {
                    // first NotStarted, store as current
                    overview.CurrentStep = status;
                    break;
                }

                // if Done
                if (overview.CurrentStep == null && status.StepStatus == NotStarted)
                {
                    // first NotStarted, store as current
                    overview.CurrentStep = status;
                }
                else if (overview.CurrentStep == null)
                {
                    // only do this when current not yet found (last item before current set is previous)
                    overview.PreviousStep = status;
                }
                else
                {
                    // set this one after current is set, then also break out of the list
                    overview.FutureStep = status;
                    break; // get out of the loop we are done
                }
            }

            return(overview);
        }
Пример #2
0
        public async void UpdateUi(bool calledFromUiThread = false)
        {
            if (!calledFromUiThread)
            {
                Activity.RunOnUiThread(() => UpdateUi(true));
                return;
            }

            this.ShowSmsSendingStatus();
            _txtCustomerName.Text = _customerSearchResult.FullName;

            _txtCustomerPhone.Text   = _customerSearchResult.Phone;
            _txtCustomerProduct.Text = _customerSearchResult.Product.DisplayName;
            bool connectedToInternet            = Resolver.Instance.Get <IConnectivityService>().HasConnection();
            RegistrationStatusOverview overview = null;

            try
            {
                ShowSteps(false);
                _txtRegistrationProcessSteps.Text = GetString(Resource.String.loading_status);
                _loadingAnimation.Visibility      = ViewStates.Visible;

                if (connectedToInternet)
                {
                    var status = await _customerSearchResult.GetStatusAsync();

                    Customer c = new Customer
                    {
                        Id        = _customerSearchResult.Id,
                        Phone     = _customerSearchResult.Phone,
                        FirstName = _customerSearchResult.FullName,
                        LastName  = _customerSearchResult.LastName
                    };

                    if (status != null && status.Steps != null && status.AdditionalInfo != null)
                    {
                        overview = await _registrationStatusService.GetVisibleSteps(c, status.Steps, status.AdditionalInfo);

                        Intent callerIntent = new Intent(this.Activity, typeof(CustomerListView));
                        callerIntent.PutExtra(CustomerListView.CustomerStatusBundled, JsonConvert.SerializeObject(status));
                        this.Activity.SetResult(Result.Ok, callerIntent);
                    }
                }
                else
                {
                    await _registrationStatusService.GetVisibleSteps(_customerSearchResult.Id);
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception);
            }
            finally
            {
                // always hide the loader
                _loadingAnimation.Visibility = ViewStates.Gone;
            }

            if (FragmentWasUnloaded)
            {
                return;
            }

            if (!connectedToInternet)
            {
                CriteriaBuilder criteriaBuilder = new CriteriaBuilder();
                var             regStatus       = await new CustomerRegistrationStepsStatusController()
                                                  .GetManyByCriteria(
                    criteriaBuilder
                    .Add("CustomerId", _customerSearchResult.Id));

                if (regStatus != null)
                {
                    var status = regStatus.OrderByDescending(reg => reg.Modified).FirstOrDefault();
                    if (status != null && !status.AdditionalInfo.IsBlank())
                    {
                        _txtExtraInformation.Text       = status.AdditionalInfo;
                        _txtExtraInformation.Visibility = ViewStates.Visible;
                    }
                }
            }
            else
            {
                if (overview != null && overview.HasCurrentStep && !overview.CurrentStep.AdditionalInfo.IsBlank())
                {
                    _txtExtraInformation.Text       = overview.CurrentStep.AdditionalInfo;
                    _txtExtraInformation.Visibility = ViewStates.Visible;
                }
            }

            if (overview == null)
            {
                ShowSteps(false);
                _txtSmsSendInfo.Visibility = SmsInfoViewState;
            }
            else
            {
                ShowSteps(true);
                _txtRegistrationProcessSteps.Text = string.Format(
                    GetString(Resource.String.registration_process_steps),
                    overview.CurrentStepNo != 0 ? overview.CurrentStepNo : overview.TotalSteps,
                    overview.TotalSteps);

                if (overview.HasPreviousStep)
                {
                    _linStepDoneNo.Visibility = ViewStates.Visible;
                    _lineStepDone.Visibility  = ViewStates.Visible;
                    _txtStepDoneNo.Text       = overview.PreviousStep.StepNumber.ToString();
                    _txtStepDone.Text         = overview.PreviousStep.StepName;
                }
                else
                {
                    _linStepDoneNo.Visibility = ViewStates.Gone;
                    _lineStepDone.Visibility  = ViewStates.Gone;
                }

                if (overview.HasCurrentStep)
                {
                    _linStepCurrentNo.Visibility = ViewStates.Visible;
                    _lineStepCurrent.Visibility  = ViewStates.Visible;
                    _txtStepCurrentNo.Text       = overview.CurrentStep.StepNumber.ToString();
                    _txtStepCurrent.Text         = overview.CurrentStep.StepName;
                }
                else
                {
                    _linStepCurrentNo.Visibility = ViewStates.Gone;
                    _lineStepCurrent.Visibility  = ViewStates.Gone;
                }

                if (overview.HasFutureStep)
                {
                    _linStepFutureNo.Visibility = ViewStates.Visible;
                    _txtStepFutureNo.Text       = overview.FutureStep.StepNumber.ToString();
                    _txtStepFuture.Text         = overview.FutureStep.StepName;
                }
                else
                {
                    _lineStepCurrent.Visibility = ViewStates.Gone;
                    _linStepFutureNo.Visibility = ViewStates.Gone;
                }
            }

            ActivityBase activity = Activity as ActivityBase;

            if (activity != null)
            {
                activity.SetScreenTitle(_customerSearchResult.FullName);
            }
        }