Example #1
0
        public rootPage(bool isUserLoggedIn)
        {
            if (isUserLoggedIn)
            {
                //set the menu list items for logged in user
                menuData data = new menuData(true);
                menuPage = new menuPage();
                menuPage.menu.ItemsSource = data;

                Master = menuPage;
                //var displayPage = new tenderEligiblePage();
                var displayPage = new tenderPage();
                //var displayPage = new accountRegistrationPage();
                Detail = new NavigationPage(displayPage);

                menuPage.menu.ItemSelected += onItemSelected;
            }
            else
            {
                //Admin is logged in
                //set the menu list items for logged in admin
                menuData data = new menuData(false);
                menuPage = new menuPage();
                menuPage.menu.ItemsSource = data;

                Master = menuPage;
                var displayPage = new announcementPage();
                Detail = new NavigationPage(displayPage);

                menuPage.menu.ItemSelected += onItemSelected;
            }
        }
        private void onCancelBtnClick(object sender, EventArgs e)
        {
            var page             = App.Current.MainPage as rootPage;
            var announcementPage = new announcementPage();

            page.changePage(announcementPage);
            //Application.Current.MainPage.Navigation.PopAsync();
        }
        async void OnSubmitButtonClicked(object sender, EventArgs e)
        {
            if (adminAuth.Username == null)
            {
                Console.WriteLine("No username");
            }
            else
            {
                Console.WriteLine("Test Username:"******"TEST Password:"******"No PASSWORD");
            }

            if (adminAuth.Username != null && adminAuth.Password != null)
            {
                activityIndicator.IsVisible = true;
                activityIndicator.IsRunning = true;

                string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostAddAnnouncement(adminAuth.Username, adminAuth.Password, titleInput.Text, contentInput.Text));

                string httpResult = httpTask.ToString();

                activityIndicator.IsVisible = false;
                activityIndicator.IsRunning = false;
                if (httpResult == "You have succesfully posted your announcement!")
                {
                    await DisplayAlert("Success", "Announcement has been successfully posted!", "OK");

                    var page             = App.Current.MainPage as rootPage;
                    var announcementPage = new announcementPage();
                    page.changePage(announcementPage);
                }
                else
                {
                    await DisplayAlert("Failed", httpResult, "OK");
                }
            }
            else
            {
                Console.WriteLine("User is not logged in");
            }
        }
Example #4
0
        async void OnDeleteButtonClicked(object sender, EventArgs e)
        {
            var answer = await DisplayAlert("Delete", "Are you sure you want to delete the announcement?", "Yes", "No");

            if (answer)
            {
                string username = "";
                username = adminAuth.Username;
                //Send HTTP request to check user exists
                Task <string> httpTask   = Task.Run <string>(() => HttpRequestHandler.deleteAnnouncement(announcementid, username));
                var           httpResult = httpTask.Result;

                if (httpResult == "deletesuccess")
                {
                    await DisplayAlert("Success", "Announcement successfully deleted", "OK");

                    var page             = App.Current.MainPage as rootPage;
                    var announcementPage = new announcementPage();
                    page.changePage(announcementPage);
                }
                else
                {
                    int count = 0;
                    while (count < 3 && httpResult != "deletesuccess")
                    {
                        Console.WriteLine("Looping for failure delete");
                        httpTask   = Task.Run <string>(() => HttpRequestHandler.deleteAnnouncement(announcementid, username));
                        httpResult = httpTask.Result;
                        count++;
                    }

                    if (httpResult != "deletesuccess")
                    {
                        await DisplayAlert("Failed", "Failed to delete announcement. Please try again later.", "OK");

                        var page             = App.Current.MainPage as rootPage;
                        var announcementPage = new announcementPage();
                        page.changePage(announcementPage);
                    }
                }
            }
        }
        async void onUpdateBtnClick(object sender, EventArgs e)
        {
            if (updateTitleError == true)
            {
                await DisplayAlert("Invalid Title", "Title cannot be empty.", "OK");
            }

            if (updateContentError == true)
            {
                await DisplayAlert("Invalid Content", "Content cannot be empty.", "OK");
            }

            if (updateTitleError == false && updateContentError == false)
            {
                updatedTitle   = editTitle.Text;
                updatedContent = editContent.Text;

                if (adminAuth.Username == null)
                {
                    Console.WriteLine("No username");
                }
                else
                {
                    Console.WriteLine("Test Username:"******"TEST Password:"******"No PASSWORD");
                }

                if (adminAuth.Username != null && adminAuth.Password != null)
                {
                    activityIndicator.IsVisible = true;
                    activityIndicator.IsRunning = true;

                    string httpTask = await Task.Run <string>(() => HttpRequestHandler.PostEditAnnouncement(adminAuth.Username, adminAuth.Password, editID, updatedTitle, updatedContent));

                    string httpResult = httpTask.ToString();

                    activityIndicator.IsVisible = false;
                    activityIndicator.IsRunning = false;

                    if (httpResult == "You have succesfully edited the announcement post!")
                    {
                        await DisplayAlert("Success", httpResult, "OK");

                        var page             = App.Current.MainPage as rootPage;
                        var announcementPage = new announcementPage();
                        page.changePage(announcementPage);
                    }
                    else
                    {
                        await DisplayAlert("Failed", httpResult, "OK");
                    }
                }
                else
                {
                    Console.WriteLine("User is not logged in");
                }
            }
        }
        async void onRegisterButtonClicked(object sender, EventArgs eventArgs)
        {
            string name = "", email = "", username = "", password = "", confPassword = "";
            var    selectedRole = rolePicker.Items[rolePicker.SelectedIndex];

            if (selectedRole == "Administrator")
            {
                selectedRole = "admin";
            }
            else if (selectedRole == "Editor")
            {
                selectedRole = "editor";
            }

            //Input error checking
            bool isInputsValid = true;

            errorLbl.Text = "";
            if (String.IsNullOrEmpty(confPasswordInput.Text) || String.IsNullOrWhiteSpace(confPasswordInput.Text))
            {
                errorLbl.Text = "Please enter Confirm Password. ";
                isInputsValid = false;
            }
            else
            {
                confPassword = confPasswordInput.Text;
            }

            if (String.IsNullOrEmpty(passwordInput.Text) || String.IsNullOrWhiteSpace(passwordInput.Text))
            {
                errorLbl.Text = "Please enter Password. ";
                isInputsValid = false;
            }
            else
            {
                password = passwordInput.Text;
            }

            if (isInputsValid)
            {
                if (confPassword != password)
                {
                    errorLbl.Text = "Password does not match. ";
                    isInputsValid = false;
                }
            }

            if (String.IsNullOrEmpty(usernameInput.Text) || String.IsNullOrWhiteSpace(usernameInput.Text))
            {
                errorLbl.Text = "Please enter Username. ";
                isInputsValid = false;
            }
            else
            {
                username = usernameInput.Text;
                if (!username.All(Char.IsLetterOrDigit))
                {
                    errorLbl.Text = "Username must be alphanumeric. ";
                    isInputsValid = false;
                }
            }

            if (String.IsNullOrEmpty(emailInput.Text) || String.IsNullOrWhiteSpace(emailInput.Text))
            {
                errorLbl.Text = "Please enter Email. ";
                isInputsValid = false;
            }
            else
            {
                email = emailInput.Text;
            }

            if (String.IsNullOrEmpty(nameInput.Text) || String.IsNullOrWhiteSpace(nameInput.Text))
            {
                errorLbl.Text = "Please enter Name. ";
                isInputsValid = false;
            }
            else
            {
                name = nameInput.Text;
                if (!Regex.IsMatch(name, @"^[a-zA-Z ]*$"))
                {
                    errorLbl.Text = "Name must be alphabetic. ";
                    isInputsValid = false;
                }
            }

            if (isInputsValid)
            {
                activityIndicator.IsVisible = true;
                activityIndicator.IsRunning = true;

                //Send HTTP request if inputs are valid
                string httpTask = await Task.Run <string>(() => HttpRequestHandler.registerNewAdmin(name, email, selectedRole, username, password, confPassword));

                string httpResult = httpTask.ToString();

                activityIndicator.IsVisible = false;
                activityIndicator.IsRunning = false;

                if (httpResult == "Account successfully registered!")
                {
                    await DisplayAlert("Success", "Account has been successfully registered!", "OK");

                    var page             = App.Current.MainPage as rootPage;
                    var announcementPage = new announcementPage();
                    page.changePage(announcementPage);
                }
                else
                {
                    await DisplayAlert("Failed", httpResult, "OK");

                    errorLbl.Text = httpResult;
                }
            }
        }