示例#1
0
        private async void BtnReq_Click(object sender, EventArgs e)
        {
            contactDonor = await fu.GetDonor(donorname);

            //await Navigation.PushAsync(new RequestItem());
            //await Navigation.PushAsync(new NavigationPage(new RequestItem()));
            await Navigation.PushModalAsync(new NavigationPage(new RequestItem(contactDonor)));
        }
示例#2
0
        //button add Donor
        async void SignUpDonorButtonClicked(object sender, EventArgs e)
        {
            ToggleIndicator();
            string confirmPassword = ConfirmPassword.Text;
            Donor  user            = new Donor()
            {
                Username  = UserUsername.Text,
                Firstname = UserFname.Text,
                Lastname  = UserLname.Text,
                Address   = UserAddress.Text,
                Email     = UserEmail.Text,
                PhoneNo   = UserContactNum.Text,
                Password  = UserPassword.Text
            };

            //validation
            var signUpSucceeded = true;

            if (string.IsNullOrWhiteSpace(user.Firstname) && string.IsNullOrWhiteSpace(user.Lastname))
            {
                signUpSucceeded = false;
                await DisplayAlert("Name error", "Name cannot be blank or contain whitespaces", "OK");

                UserFname.Text = string.Empty;
                UserLname.Text = string.Empty;
            }

            if (string.IsNullOrWhiteSpace(user.Address))
            {
                signUpSucceeded = false;
                await DisplayAlert("Address error", "Address cannot be blank or contain whitespaces", "OK");

                UserAddress.Text = string.Empty;
            }

            if (string.IsNullOrWhiteSpace(user.Email) && !user.Email.Contains("@"))
            {
                signUpSucceeded = false;
                await DisplayAlert("Email format error", "Email must be in a typical email format", "OK");

                UserEmail.Text = string.Empty;
            }


            if (string.IsNullOrWhiteSpace(user.Username))
            {
                signUpSucceeded = false;
                await DisplayAlert("Username error", "Address cannot be blank or contain whitespaces", "OK");

                UserUsername.Text = string.Empty;
            }
            var person = await fb.GetDonor(user.Username);

            if (person != null)
            {
                await DisplayAlert("Error", "A person with that usernane already exist", "OK");

                signUpSucceeded   = false;
                UserUsername.Text = string.Empty;
            }

            string errormsg;

            if (!ValidatePassword(user.Password, out errormsg))
            {
                signUpSucceeded = false;
                await DisplayAlert("Weak Password", errormsg, "OK");

                UserPassword.Text    = string.Empty;
                ConfirmPassword.Text = string.Empty;
            }

            if (user.Password != confirmPassword)
            {
                signUpSucceeded = false;
                await DisplayAlert("Passwords mismatch", "Passwords don't match", "OK");

                ConfirmPassword.Text = string.Empty;
            }

            if (signUpSucceeded)
            {
                var rootpage = Navigation.NavigationStack.FirstOrDefault();
                if (rootpage != null)
                {
                    await fb.AddDonor(UserUsername.Text, UserFname.Text, UserLname.Text, UserAddress.Text, UserEmail.Text, UserContactNum.Text, UserPassword.Text);

                    App.IsUserLoggedIn  = true;
                    Global.currentDonor = user;
                    Global.currentRep   = null;
                    // Navigation.InsertPageBefore(new MainPage(), Navigation.NavigationStack.FirstOrDefault());
                    // await Navigation.PopToRootAsync();
                    //await Navigation.PushAsync(new MainPage());  //back button works. bad code
                    Application.Current.MainPage = new MainPageDonor();
                }
                else
                {
                    await DisplayAlert("Failed", "Signup Error", "OK");
                }
            }
            ToggleIndicator();
        }
示例#3
0
        async void Login_Clicked(object sender, EventArgs e)
        {
            IsBusy = true;
            string Username = LoginUsername.Text;
            string Password = LoginPassword.Text;

            if (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Password))
            {
                await DisplayAlert("Empty Fields", "Please enter both credentials", "OK");
            }

            else
            {
                if (LoginUser.Equals("Donor"))
                {
                    Donor user = await fe.GetDonor(Username);

                    if (user != null)
                    {
                        if (Username == user.Username && Password == user.Password)
                        {
                            App.IsUserLoggedIn  = true;
                            Global.currentDonor = user;
                            // Navigation.InsertPageBefore(new MainPage(), this);
                            // await Navigation.PopAsync();
                            Application.Current.MainPage = new MainPageDonor();
                            IsBusy = false;

                            //redirect to another =mainpaege
                        }
                        else
                        {
                            await DisplayAlert("Login Fail", "Please enter correct password", "OK");

                            LoginPassword.Text = string.Empty;
                        }
                    }
                    else
                    {
                        await DisplayAlert("Login Fail", "User not found", "OK");
                    }
                }
                else if (LoginUser.Equals("Institution"))
                {
                    Institution user = await fe.GetRepresentative(Username);

                    if (user != null)
                    {
                        if (Username == user.Username && Password == user.Password)
                        {
                            App.IsUserLoggedIn = true;
                            Global.currentRep  = user;
                            // Navigation.InsertPageBefore(new MainPage(), this);
                            // await Navigation.PopAsync();
                            Application.Current.MainPage = new MainPage();
                            //redirect to another =mainpaege
                        }
                        else
                        {
                            await DisplayAlert("Login Fail", "Please enter correct password", "OK");

                            LoginPassword.Text = string.Empty;
                        }
                    }
                    else
                    {
                        await DisplayAlert("Login Fail", "User not found", "OK");
                    }
                }
                else
                {
                    await DisplayAlert("Choose user", "Please enter user type", "OK");
                }
            }
        }