Ejemplo n.º 1
0
        async void RegisterProcedure(object sender, EventArgs e)
        {
            //TODO: other password and email checks
            if (Entry_Password.Text != Entry_RepeatPassword.Text)
            {
                await DisplayAlert("Register", "The two passwords you typed do not match. Try again.", "Ok");
            }
            else
            {
                Debug.WriteLine("Register: New User object.");
                RegisterView user = new RegisterView
                {
                    FirstName       = Entry_FirstName.Text,
                    LastName        = Entry_LastName.Text,
                    Email           = Entry_Email.Text,
                    Password        = Entry_Password.Text,
                    ConfirmPassword = Entry_RepeatPassword.Text,
                    BirthDate       = DatePicker_Birthday.Date,
                    Gender          = Picker_Gender.SelectedItem.ToString()
                };

                Debug.WriteLine("Register: Check if all fields are completed.");
                if (user.CheckNullInformation())
                {
                    var result = false;
                    //TODO: check for InternetConnection before calling the webserver
                    try
                    {
                        //Register API call
                        result = await App.RestService.Register(user);
                    }
                    catch (NullReferenceException)
                    {
                        Console.WriteLine("NullReferenceException in Register.");
                        result = false;
                    }
                    catch (TaskCanceledException)
                    {
                        result = false;
                        Console.WriteLine("TaskCanceledException in Register.");
                        await DisplayAlert("Register", "Not able to reach server in time.", "Ok");
                    }

                    Debug.WriteLine("Register: Check result from API.");
                    if (result)
                    {
                        await DisplayAlert("Register", "You successfully registered. You can now login.", "Ok");

                        //go to LoginPage
                        if (Device.RuntimePlatform == Device.Android)
                        {
                            Application.Current.MainPage = new LoginPage();
                        }
                        else if (Device.RuntimePlatform == Device.iOS)
                        {
                            await Navigation.PushModalAsync(new LoginPage());
                        }
                    }
                }
            }
        }