Ejemplo n.º 1
0
        private async void loadUsers()
        {
            users = await ApiWrapper.GetUsers(); //Using API to fetch the students

            foreach (var u in users)
            {
                emailAutoComplete.Add(u.Email); //Autocompletes the email address
            }
        }
Ejemplo n.º 2
0
        private async void bunifuThinButton3_Click(object sender, EventArgs e)
        {
            string name = nameTextBox.Text;
            string path = fileTextBox.Text;

            string error = "";

            string specialChar = @"\|!#$%&/()=?»«@£§€{}.-;'<>_,";

            foreach (var item in specialChar)
            {
                if (name.Contains(item))
                {
                    MessageBox.Show("Please enter a name without special characters.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }



            //simple validation to verify against name - prevents clustering when adding larger classes
            if (name.Length < 3)
            {
                error = "Name is too short.";
            }
            else if (!File.Exists(path))
            {
                error = "Specified file does not exist.";
            }

            if (error != "")
            {
                MessageBox.Show(error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //debugging, shows user error
                return;
            }

            try
            {
                string url = await ApiWrapper.UploadFile(path);

                if (!await ApiWrapper.CreateHomework(classObj.Id, name, url))                                           //attempts to create homework
                {
                    MessageBox.Show("Failed to create homework.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //throws error if anything failed
                }
                else
                {
                    //homework was created
                    Close();
                }
            }
            catch
            {
                MessageBox.Show("It seem's the file is open, close it and try again..."); //likely scanerio when attaching files.
            }
        }
Ejemplo n.º 3
0
        //Saving the class name
        private async void saveNameButton_Click(object sender, EventArgs e)
        {
            string name = nameTextBox.Text;

            if (name.Length < 3) //Verification on class name, ensures teacher enters an appropiate name.
            {
                MessageBox.Show("Name is too short.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                await ApiWrapper.UpdateClass(classObj.Id, name); //If criteria is met, update will also apply to the backend too
            }
        }
Ejemplo n.º 4
0
        private async void bunifuThinButton1_Click(object sender, EventArgs e)
        {
            string name = nameTextBox.Text;

            if (name.Length < 3) //Verification on class name, ensures teacher enters an appropiate name.
            {
                MessageBox.Show("Name is too short.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                await ApiWrapper.UpdateClass(classObj.Id, name);
            }
        }
Ejemplo n.º 5
0
        //Create a class
        private async void bunifuThinButton3_Click(object sender, EventArgs e)
        {
            var dialog = new CreateClassDialog(); //Constructor - creating new ClassDialog

            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                string name    = dialog.Name;
                bool   success = await ApiWrapper.CreateClass(name); //Parses upates on the Dialog to the API which updates the class information on the backend.

                sync();
            }
            dialog.Dispose();
        }
Ejemplo n.º 6
0
 //
 private async void bunifuThinButton2_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem i in listView1.SelectedItems) //Remove the selected item from the list.
     {
         if (i.Tag is User)
         {
             User u = (User)i.Tag;
             if (await ApiWrapper.RemoveStudentFromClass(classObj.Id, u.Id)) //If criteria is met, update will also apply to the backend too
             {
                 listView1.Items.Remove(i);                                  //Remove that selected Tagged student.
             }
         }
     }
 }
Ejemplo n.º 7
0
 //Removing students from a Class.
 private async void removeButton_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem i in listView1.SelectedItems) //Remove the selected item from the list.
     {
         if (i.Tag is User)
         {
             User u = (User)i.Tag;
             if (await ApiWrapper.RemoveStudentFromClass(classObj.Id, u.Id)) //Update the database, so change has been applied serverside.
             {
                 listView1.Items.Remove(i);
             }
         }
     }
 }
Ejemplo n.º 8
0
        private async void update()                   //Syncs fields on the form with the database.
        {
            var hw = await ApiWrapper.GetHomeworks(); //Calls method from the class ApiWrapper

            listView1.Items.Clear();
            foreach (var h in hw) //iteration
            {
                string submitted = h.Submitted ? "Yes" : "No";
                var    item      = new ListViewItem(new[] { h.Name, h.ClassName, h.TeacherName, h.Url, submitted }); //Construting new ListItem containg all entites needing for the students such as ClassName, Teacher, Homework etc...
                item.Tag = h;
                listView1.Items.Add(item);
            }
            listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); //AutoReizes properties, allows users to customise the list to their liking.
        }
Ejemplo n.º 9
0
        private async void bunifuThinButton3_Click(object sender, EventArgs e)
        {
            string email = emailTextBox.Text; //Privately declared varible to store Student's email.

            try
            {
                //find the user with the entered email address
                User u = users.First(x => x.Email == email);
                if (await ApiWrapper.AddStudentToClass(classObj.Id, u.Id))
                {
                    var item = new ListViewItem(new[] { u.Name, u.Email });
                    item.Tag = u;
                    listView1.Items.Add(item); //Adds the selected student to the class.
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message); //Error logging, helps in terms of debugging
            }
        }
Ejemplo n.º 10
0
        //Fetch and update the applicastions dropDown with all updated variables from the Backend.
        private async void sync()
        {
            if (classes != null)
            {
                classes.Clear(); //Cleares current classes so fresh list can be imported, - prevents collision of data.
            }
            bunifuDropdown1.Clear();
            classes = await ApiWrapper.GetClasses(); //Fetches all the latest classes from the WebHost

            foreach (var i in classes)
            {
                bunifuDropdown1.AddItem(i.Name); //Adds new item down into the List.
            }

            //Verification that DropDown has successfully updated if the DropDown is set to 0.
            if (bunifuDropdown1.Items.Length > 0)
            {
                bunifuDropdown1.selectedIndex = 0;
                update(); //Calls Update, responsible for populating all devices
            }
        }
Ejemplo n.º 11
0
        private async void bunifuThinButton3_Click(object sender, EventArgs e)
        {
            bool auth = await ApiWrapper.Authenticate(textBox1.Text, textBox2.Text);

            if (auth)
            {
                Hide();
                if (Form1.LoginType == LoginType.STUDENT)
                {
                    //show student panel
                    Form3.instance.Show();
                }
                else
                {
                    //show teacher panel
                    Form2.instance.Show();
                }
            }
            else
            {
                MessageBox.Show("Invalid email or password", "Login failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 12
0
        //Once the DropDown has been updated, this causes the Lists and dataGrid to update.
        private async void update()
        {
            Console.WriteLine("update");
            Class c = await ApiWrapper.GetClass(selectedClass.Id);

            selectedClass = c;

            List <StudentHomework> shw = null;

            if (c.LastHomework != 0)
            {
                Console.WriteLine("lasthw: " + c.LastHomework);
                shw = await ApiWrapper.GetStudentHomeworks(c.LastHomework ?? 0);  //Fetches studentHomwork, uses ApiWrapper to fetch appropiate data from Backend.
            }

            bunifuCircleProgressbar1.ResetText();
            bunifuCircleProgressbar1.MaxValue = c.Students.Count > 0 ? c.Students.Count : 1;
            int submitCount = 0;

            listView1.Items.Clear();
            foreach (var s in c.Students)
            {
                string submitted = "No";
                if (shw != null && shw.Exists(x => x.StudentId == s.Id)) //Verifies whether each student has submitted homework.
                {
                    submitted = "Yes";
                    submitCount++;
                }
                var item = new ListViewItem(new[] { s.Name, s.Email, submitted });  //Repopulate the ListView with all student information.
                item.Tag = shw.Find(X => X.StudentId == s.Id);
                listView1.Items.Add(item);
            }

            bunifuCircleProgressbar1.Value = submitCount; //Updates the CircleProgessBar depending on how many students have submitted.

            bunifuCircleProgressbar1.Refresh();
        }
Ejemplo n.º 13
0
        //submit homework
        private async void bunifuThinButton3_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 1) //ensures that student has an entity to where they will send homework too.
            {
                var item = listView1.SelectedItems[0];
                var hw   = (Homework)item.Tag;

                OpenFileDialog ofd = new OpenFileDialog();
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    string url = await ApiWrapper.UploadFile(ofd.FileName); //url contains name of file, easy referencing when looking for it manually

                    await ApiWrapper.SubmitHomework(hw.Id, url);
                }
            }
            else if (listView1.SelectedItems.Count == 0) //error handling
            {
                MessageBox.Show("Please select an item from the list!", "No item selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Please select only one item!", "Multiple items selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Ejemplo n.º 14
0
        private async void bunifuThinButton1_Click(object sender, EventArgs e)
        {
            //privately declared variables, each corresponding to their details.
            string name      = nameTextBox.Text;
            string email     = emailTextBox.Text;
            string password  = passwordTextBox.Text;
            bool   isTeacher = teacherCheckBox.Checked;
            bool   register  = false;

            if (name != "" && email != "" && password != "") //ensures user does not leave fields blank
            {
                int eLength = email.Length;
                int pLength = password.Length;

                if (pLength < 9)
                {
                    MessageBox.Show("Please enter a stronger password", "Failed to create account", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }

                if (eLength > 32)
                {
                    MessageBox.Show("Please enter a suitable email length", "Failed to create account", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }

                bool containsInt = name.Any(char.IsDigit);

                if (containsInt == true)
                {
                    MessageBox.Show("No digits allowed in your name!", "Failed to create account", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }

                string specialChar = @"\|!#$%&/()=?»«@£§€{}.-;'<>_,";
                foreach (var item in specialChar)
                {
                    if (name.Contains(item))
                    {
                        MessageBox.Show("Please enter a name without special characters.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        register = true;
                    }
                }

                if (email.Contains('@'))
                {
                    if (email.Contains('.'))
                    {
                    }
                }
                else
                {
                    MessageBox.Show("Invalid email format detected...", "Failed to create account", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }

                if (register == true)
                {
                    if (await ApiWrapper.CreateUser(name, email, password, isTeacher)) //Creates account
                    {
                        MessageBox.Show("Your account was created", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        Close();
                    }
                    else //error handling
                    {
                        MessageBox.Show("Your account could not be created", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("Please fill out all fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //Shows if they did not enter in all fields.
            }
        }