Exemple #1
0
        /* Function for when the user clicks the next button. It runs validation on the data entered by the user on the page. If a field is
         * left blank or not filled out properly it displays an alert with the errors, otherwise it sends the user to the RegisterAddress page
         */
        async Task NextButtonClicked()
        {
            CustomerDetailsValidator customer_details_validator = new CustomerDetailsValidator();
            ValidationResult         results = customer_details_validator.Validate(account);

            if (!results.IsValid)
            {
                String result_messages = results.ToString("\n");
                await Application.Current.MainPage.DisplayAlert("Error", result_messages, "OK");
            }
            else
            {
                await Application.Current.MainPage.Navigation.PushAsync(new RegisterAddressPage());
            }
        }
        async Task CreateAccountButtonClicked()
        {
            CustomerDetailsValidator account_details_validator = new CustomerDetailsValidator();
            ValidationResult         results = account_details_validator.Validate(account); //validate account data

            if (!results.IsValid)
            {
                String result_messages = results.ToString("\n");
                await Application.Current.MainPage.DisplayAlert("Error", result_messages, "OK");
            }
            else
            {
                switch (account_level)
                {
                case 1:
                    account.Admin = new Admin();
                    break;

                case 2:
                    account.CarePartner         = new CarePartner();
                    account.CarePartner.Company = "Default";
                    break;

                case 3:
                    account.Customer = new Customer();
                    break;
                }

                RegisterService registerModel = new RegisterService(account);
                try //to save account entry to db
                {
                    await registerModel.CreateCognitoUser();

                    await registerModel.CreateDatabaseUser(account, account_level);

                    await Application.Current.MainPage.DisplayAlert("Account Created", " ", "OK");

                    await Application.Current.MainPage.Navigation.PushAsync(new AdminNavBar());
                }
                catch (Exception e)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", e.Message, "OK");
                }
            }
        }