Esempio n. 1
0
        private async void Btn_CreateAccount_Clicked(object sender, EventArgs e)
        {
            try
            {
                (sender as Button).IsEnabled = false;
                UserDialogs.Instance.ShowLoading("Please Wait...");
                this.IsEnabled = false;

                RegistrationModel user = new RegistrationModel(Entry_Password.Text, Entry_Password1.Text, Entry_Email.Text, Entry_Username.Text, Entry_DOB.Date);


                if (user.CheckInformation() && user.CheckPass())
                {
                    var loginResponse = await App.RestService.PostResponse_HTTPRESPONSE(Constants.APIURL + "useraccount/Register", JsonConvert.SerializeObject(user));

                    if (loginResponse.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        UserAccount newUser = new UserAccount(user.Username, user.Password);
                        App.UserDatabase.SaveUser(newUser);
                        Application.Current.MainPage = new NavigationPage(new CustomerTabbedPage());
                    }
                    else
                    {
                        await DisplayAlert("Login Failed", "Login credentials not correct or something went wrong", "Ok");

                        UserDialogs.Instance.HideLoading();

                        (sender as Button).IsEnabled = true;
                        this.IsEnabled = true;
                    }
                }
                else
                {
                    await DisplayAlert("Login Failed", "Entered value not valid", "Ok");

                    try
                    {
                        UserDialogs.Instance.HideLoading();
                    }
                    catch (Exception ex)
                    {
                    }
                    (sender as Button).IsEnabled = true;
                    this.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Login Failed", "Something went wrong check your connection", "Ok");

                try
                {
                    UserDialogs.Instance.HideLoading();
                }
                catch (Exception eex)
                {
                }
            }
            (sender as Button).IsEnabled = true;
            this.IsEnabled = true;

            clm_Email.IsVisible         = false;
            clm_DOB.IsVisible           = false;
            clm_Pass1.IsVisible         = false;
            Btn_SignIn.IsVisible        = true;
            Btn_Register.IsVisible      = true;
            Btn_CreateAccount.IsVisible = false;
        }