/* This function is run when the user clicks the Create Account button. It first validates the data on the page and displays an error if there is any
         * missing or incorrect data. If no errors exist it uses the RegisterService class and creates a new Cognito user in AWS as well creates a user and stores
         * their information in the database. Redirects user to login page upon successful registration.
         */
        async void CreateAccountClicked()
        {
            CustomerAddressValidator customer_address_validator = new CustomerAddressValidator();
            ValidationResult         results = customer_address_validator.Validate(address);

            if (!results.IsValid)
            {
                String result_messages = results.ToString("\n");
                await Application.Current.MainPage.DisplayAlert("Error", result_messages, "OK");
            }
            else
            {
                RegisterService registerModel = new RegisterService(account, address);

                try
                {
                    await registerModel.CreateCognitoUser();

                    await registerModel.CreateDatabaseUser(account);

                    await registerModel.AddAddress(address);

                    await Application.Current.MainPage.DisplayAlert("Success", "Account created succesfully. Please check your email for verification link", "OK");

                    await Application.Current.MainPage.Navigation.PushAsync(new LoginPage());
                }
                catch (Exception e)
                {
                    await Application.Current.MainPage.DisplayAlert("Error", e.Message, "OK");
                }
            }
        }
        public void Setup()
        {
            _customerloadValidator = new CustomerLoadValidator();
            _customer = new CustomerLoad();

            _customerAddressValidator = new CustomerAddressValidator();
            _cusotmerAddress          = new CustomerAddress();
        }
Ejemplo n.º 3
0
        public void Validate_ValidCountry_CheckPassed()
        {
            var address = new CustomerAddress(Factory.CustomerAddressUSA);

            var validator = new CustomerAddressValidator(address);

            validator.Validate();

            CMSAssert.All(
                () => Assert.IsFalse(validator.CheckFailed),
                () => Assert.IsFalse(validator.CountryNotSet),
                () => Assert.IsFalse(validator.StateNotFromCountry)
                );
        }
Ejemplo n.º 4
0
        public void Validate_StateNotFromCountry_CheckFailed()
        {
            var address = new CustomerAddress(Factory.CustomerAddressUSA);

            address.State = mStateFromUnknownCountry;

            var validator = new CustomerAddressValidator(address);

            validator.Validate();

            CMSAssert.All(
                () => Assert.IsTrue(validator.CheckFailed),
                () => Assert.IsTrue(validator.StateNotFromCountry)
                );
        }
Ejemplo n.º 5
0
        public void Validate_CountryNotSet_CheckFailed()
        {
            var address = new CustomerAddress(Factory.CustomerAddressUSA);

            address.Country = null;

            var validator = new CustomerAddressValidator(address);

            validator.Validate();

            CMSAssert.All(
                () => Assert.IsTrue(validator.CheckFailed),
                () => Assert.IsTrue(validator.CountryNotSet)
                );
        }
        //add an aditional address to customer account
        async void AddAddressClicked()
        {
            CustomerAddressValidator customer_address_validator = new CustomerAddressValidator();
            ValidationResult         results = customer_address_validator.Validate(address); //validate address

            if (!results.IsValid)                                                            //invalid - show error
            {
                String result_messages = results.ToString("\n");
                await Application.Current.MainPage.DisplayAlert("Error", result_messages, "OK");
            }
            else //valid try to save address
            {
                AddressRestService          addressRestService          = new AddressRestService();
                Customer_AddressRestService customer_AddressRestService = new Customer_AddressRestService();
                Address created_address = await addressRestService.SaveAddressAsync(address, true); //save address entry to db

                Customer_Address customer_Address = new Customer_Address();

                //gather customer_address data
                customer_Address.CustomerID   = (int)Application.Current.Properties["customerID"];
                customer_Address.AddressID    = created_address.AddressID;
                customer_Address.AddressLabel = customer_address.AddressLabel;
                try //to save customer_address entry to db
                {
                    await customer_AddressRestService.SaveCustomer_AddressAsync(customer_Address, true);

                    await Application.Current.MainPage.DisplayAlert("Success", "Address Saved", "OK");

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