private void Button_Update(object sender, RoutedEventArgs e)
 {
     GetUsersFromApi.RetrieveUsersFromApi();
     if (userId == null || firstName.Text == "" || lastName.Text == "" || password.Text == "" || email.Text == "")
     {
         MessageBox.Show("All fields must be filled in please");
     }
     else
     {
         MessageBox.Show(PutUsers.UpdateUsers(int.Parse(userId.Text), firstName.Text, lastName.Text, password.Text, email.Text, username));
         MessageBox.Show("If you updated yoour password, remember to log in with it next time");
     }
 }
        private void Button_Login(object sender, RoutedEventArgs e)
        {
            GetUsersFromApi.RetrieveUsersFromApi();
            username = enteredUsername.Text;

            int enteredUnameId = Array.FindIndex(usersList.ToArray(), row => row.Uname == username);
            int enteredPassId  = Array.FindIndex(usersList.ToArray(), row => row.Passwrd == enteredPassword.Text);

            // Retrieved from https://stackoverflow.com/questions/4388600/getting-the-index-of-a-particular-item-in-array

            if (enteredUnameId >= 0 && enteredUnameId == enteredPassId)
            {
                userId.Text = $"{ usersList[enteredUnameId].Id}";

                firstName.Text         = $"{ usersList[enteredUnameId].Fname}";
                lastName.Text          = $"{ usersList[enteredUnameId].Lname}";
                password.Text          = $"{ usersList[enteredUnameId].Passwrd}";
                email.Text             = $"{ usersList[enteredUnameId].Email}";
                updateButton.IsEnabled = true;
                searchButton.IsEnabled = true;
                detailButton.IsEnabled = true;
                removeButton.IsEnabled = true;
                loginButton.IsEnabled  = false;

                switchButton.IsEnabled = true;

                loggedInUserId = int.Parse(userId.Text);

                //WishlistGrid.ItemsSource = titles; ----> Retrieved from http://dotnetpattern.com/wpf-listview-binding

                // Saved movies' titles would be displayed once the user logs in

                WishlistGrid.ItemsSource = GetNoDuplicateTitles();
                enteredUsername.Text     = $"";
                enteredPassword.Text     = $"";

                DisplayNoDetails();
            }
            else
            {
                MessageBox.Show("Username or password is incorrect.\n\nPlease try again.");
            }
        }
        private void Button_Switch(object sender, RoutedEventArgs e)
        {
            GetUsersFromApi.RetrieveUsersFromApi();

            // Application.Current.Shutdown();

            loginButton.IsEnabled = true;
            DisplayNoDetails();
            userId.Text    = "";
            firstName.Text = "";
            lastName.Text  = "";
            password.Text  = "";
            email.Text     = "";

            updateButton.IsEnabled = false;
            searchButton.IsEnabled = false;
            detailButton.IsEnabled = false;
            removeButton.IsEnabled = false;
            switchButton.IsEnabled = false;
        }
Example #4
0
        public void Start()
        {
            List <Users>  usersList = GetUsersFromApi.RetrieveUsersFromApi();
            List <string> fNameList = new List <string>();
            List <string> lNameList = new List <string>();

            for (int id = 0; id < usersList.Count; id++)
            {
                fNameList.Add(usersList[id].Fname);
                lNameList.Add(usersList[id].Lname);
            }

            int FirstNameId = fNameList.FindIndex(f => f.Contains(registerFName.Text));

            int LastNameId = lNameList.FindIndex(l => l.Contains(registerLName.Text));

            if (registerFName.Text != "" && registerLName.Text != "" && registerPassword.Text != "" && registerEmail.Text != "")
            {
                if (FirstNameId >= 0 && FirstNameId == LastNameId)
                {
                    MessageBox.Show("This user's already registered. \n\nPlease login.");
                }
                else
                {
                    char firstChar = registerFName.Text.ToString().ToUpper()[0]; // In C#, ToUpper() is a string method

                    string lowerLastName = registerLName.Text.ToString().ToLower();

                    string secondPart = char.ToUpper(lowerLastName[0]) + lowerLastName.Substring(1);

                    string newUserName = firstChar + secondPart;
                    PostUsers.AddUsers(registerFName.Text, registerLName.Text, registerPassword.Text, registerEmail.Text, newUserName);
                    MessageBox.Show("Your username: "******"{newUserName}" + "\n\nYou could log in with your username & password now!");
                }
            }
            else
            {
                MessageBox.Show("Please fill in all fields then cliclk the button again");
            }
        }
 public MainWindow()
 {
     InitializeComponent();
     enteredUsername.Focus();
     GetUsersFromApi.RetrieveUsersFromApi(); // Get updated users from API
 }
Example #6
0
 private void Button_Register(object sender, RoutedEventArgs e)
 {
     GetUsersFromApi.RetrieveUsersFromApi();
     Start();
 }