Beispiel #1
0
        /// <summary>
        /// Asynchronous handler activated when the user clicks the Login button.
        /// </summary>
        private async void LoginButton_ClickAsync()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                //Get the user oauth token
                OAuthTokenDetail oauthTokenDetail = await ClientLibraryFacade.LoginAsync(
                    LoginIdTextBox.Text,
                    PasswordTextBox.Text,
                    ClientIdTextBox.Text);

                //Get the user company expense configuration needed to submit expense reports.
                var groupConfig = await ClientLibraryFacade.GetGroupConfigurationAsync();

                //Determine the default expense policy out of the expense configuration,
                //so that the default policy will be selected by default on the UI.
                var policies           = groupConfig.Policies;
                int defaultPolicyIndex = -1;
                for (int i = 0; i < policies.Length; i++)
                {
                    if (policies[i].IsDefault.Value)
                    {
                        defaultPolicyIndex = i;
                        break;
                    }
                }

                //Display the list of expense policies obtained from the company configuration
                //and select the default policy
                ExpensePolicyListBox.DisplayMember = "Name";
                ExpensePolicyListBox.Items.AddRange(groupConfig.Policies);
                if (defaultPolicyIndex != -1)
                {
                    ExpensePolicyListBox.SelectedIndex = defaultPolicyIndex;
                }

                //Display the list of allowed payment types obtained from the company configuration.
                PaymentTypeComboBox.DisplayMember = "Name";
                PaymentTypeComboBox.Items.AddRange(groupConfig.PaymentTypes);
                if (groupConfig.PaymentTypes.Length > 0)
                {
                    PaymentTypeComboBox.SelectedIndex = 0;
                }

                //Display the oauth token obtained from the user login.
                OAuthTokenTextBox.Text         = oauthTokenDetail.AccessToken;
                CreateEverythingButton.Enabled = true;
            }
            catch (Exception except)
            {
                DisplayException(except);
            }
            finally {
                this.Cursor = Cursors.Default;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Process asynchronously the Login button click.
        /// </summary>
        protected async void LoginAsync()
        {
            try
            {
                // Clear status
                TextView statusView = FindViewById <TextView>(Resource.Id.statusTextView);
                statusView.Text = "";

                // Find the objects for Login view, Password view, and Client ID view
                var clientIdView = FindViewById <EditText>(Resource.Id.clientIdEditText);
                var loginIdView  = FindViewById <EditText>(Resource.Id.loginIdEditText);
                var passwordView = FindViewById <EditText>(Resource.Id.passwordEditText);

                // Facade calls Concur API to Login using the user provided LoginID, Password, and ClientID
                await ClientLibraryFacade.LoginAsync(loginIdView.Text, passwordView.Text, clientIdView.Text);

                // Facade calls Concur API to get the expense configuration needed by this use in order to create expense reports.
                ExpenseGroupConfiguration defaultGroupConfig = await ClientLibraryFacade.GetGroupConfigurationAsync();

                // Determine which expense policy is the default one.
                Policy defaultExpensePolicy = null;
                foreach (Policy policy in defaultGroupConfig.Policies)
                {
                    if (policy.IsDefault == true)
                    {
                        defaultExpensePolicy = policy;
                    }
                }

                // Determine, out of the expense configuration object, the allowed Expense Types and allowed Payment Types for this user
                expenseTypes = defaultExpensePolicy.ExpenseTypes;
                paymentTypes = defaultGroupConfig.PaymentTypes;
                var expenseTypeNames = new List <string>(); foreach (var type in expenseTypes)
                {
                    expenseTypeNames.Add(type.Name);
                }
                var paymentTypeNames = new List <string>(); foreach (var type in paymentTypes)
                {
                    paymentTypeNames.Add(type.Name);
                }

                // Populate the appropriate UI views for Payment Types and Expense Types
                PopulateSpinner(expenseTypeNames, Resource.Id.expenseTypeSpinner);
                PopulateSpinner(paymentTypeNames, Resource.Id.paymentTypeSpinner);
            }
            catch (Exception except)
            {
                DisplayException(except);
            }
        }
        /// <summary>
        /// Asynchronous processing of the login button click.
        /// </summary>
        async void LoginButton_TouchUpInsideAsync()
        {
            try
            {
                // Clear the last displayed status.
                StatusLabel.Text = "";

                // The facade calls Concur API to login using the ClientID, LoginID, and Password entered by the user in the UI.
                await ClientLibraryFacade.LoginAsync(
                    LoginIdTextField.Text,
                    PasswordTextField.Text,
                    ClientIdTextField.Text);

                // The facade calls Concur API to get the configuration this user should use when creating expense reports.
                // Then get the list of allowed Payment Types and allowed Expense Types for this user for creating expense reports.
                var groupConfig = await ClientLibraryFacade.GetGroupConfigurationAsync();

                PaymentTypes = groupConfig.PaymentTypes;
                ExpenseTypes = groupConfig.Policies.First(p => p.IsDefault.Value == true).ExpenseTypes;

                // Display the Payment Types and the Expense Types
                (ExpenseTypePicker.Model as MyPickerModel).MyItems = ExpenseTypes.Select(t => t.Name).ToList();
                (PaymentTypePicker.Model as MyPickerModel).MyItems = PaymentTypes.Select(t => t.Name).ToList();

                // Refresh controls used for displaying and selecting Payment Type and Expense Type.
                ExpenseTypePicker.ReloadAllComponents();
                PaymentTypePicker.ReloadAllComponents();
                SetButtonTitleAsPickerSelection(ExpenseTypeExpandButton, ExpenseTypePicker);
                SetButtonTitleAsPickerSelection(PaymentTypeExpandButton, PaymentTypePicker);

                CreateReportButton.Enabled = true;
            }
            catch (Exception e)
            {
                DisplayException(e);
            }
        }