///<summary> ///Check whether student is enrolled ///</summary> ///<param name = "studName">Student's username</param> public async Task <bool> CheckStudEnroll(string studName) { DatabaseQAHandler.GetCourse(courseName, course => { for (int i = 0; i < (course.students).Count; i++) // Loop through List { Debug.Log("STUDENT[I]" + course.students[i]); Debug.Log("studname:" + studName); if (studName == course.students[i]) { Debug.Log("SAMEE"); chk = true; } } }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("check stud enroll elapsed milliseconds: {0}" + sec + ", Chk is " + chk); return(chk); }
///<summary> ///Delete course in database ///</summary> public async void DeleteCourse() { loader.SetActive(true); Debug.Log("DELETE name: " + courseKey); DatabaseQAHandler.DeleteCourse(courseKey, () => { }); DatabaseQAHandler.GetCourseLvlQns(courseLvlQns => { foreach (var courseLvlQn in courseLvlQns) { //Debug.Log($"{course.Key} {course.Value.userName}"); if (courseLvlQn.Value.courseName == courseKey) //Find course created by you { DatabaseQAHandler.DeleteCourseLvlQn(courseLvlQn.Key, () => { }); } } }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Delete elapsed milliseconds: {0}" + sec); await Read(); loader.SetActive(false); messageBox.SetActive(true); messageBox.transform.GetChild(1).GetComponent <Text>().text = courseKey + " deleted successfully."; courseKey = null; }
///<summary> ///Check whether the student username is valid ///</summary> ///<param name = "studName">Student's username</param> public async Task <bool> CheckStudValid(string studName) { DatabaseQAHandler.GetUsers(userDatas => { foreach (var userData in userDatas) { Debug.Log($"{userData.Value.userName}"); if (userData.Value.userName == studName) { Debug.Log("USERNAME VALIG"); chkStudValid = true; // Student username is valid } } }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("check stud exist elapsed milliseconds: {0}" + sec + ", Chk Valid is " + chkStudValid); return(chkStudValid); }
///<summary> ///Check for existing question ///</summary> ///<param name = "qn">Question Input</param> public async Task <bool> CheckQnExist(string qn) { DatabaseQAHandler.GetCourseLvlQn(key, courseLvlQn => { //courseLvlQnCreate = courseLvlQn; for (int i = 0; i < (courseLvlQn.qns).Count; i++) // Loop through List { if (qn == courseLvlQn.qns[i]) { chk = true; } } }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(500).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("check qn exist elapsed milliseconds: {0}" + sec + ", Chk is " + chk); return(chk); }
///<summary> ///Create rows for the list of questions and answers created ///</summary> public async Task Read() { count = 0; for (int i = 0; i < itemParent.transform.childCount; i++) { Destroy(itemParent.transform.GetChild(i).gameObject); } DatabaseQAHandler.GetCourseLvlQn(key, courseLvlQn => { courseLvlQnCreate = courseLvlQn; int number = 1; for (int i = 0; i < (courseLvlQn.qns).Count; i++) // Loop through List { GameObject tmp_item = Instantiate(item, itemParent.transform); tmp_item.name = i.ToString(); Debug.Log("here item name: " + tmp_item.name); tmp_item.transform.GetChild(0).GetComponent <Text>().text = number.ToString(); tmp_item.transform.GetChild(1).GetComponent <Text>().text = courseLvlQn.qns[i]; tmp_item.transform.GetChild(2).GetComponent <Text>().text = (courseLvlQn.ans[i]).ToString(); number++; count++; } }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Read elapsed milliseconds: {0}" + sec + "Count:" + count); }
public async Task <bool> CheckLvlExist(int lvlNo) { DatabaseQAHandler.GetCourseLvlQns(courseLvlQns => { foreach (var courseLvlQn in courseLvlQns) { Debug.Log($"{courseLvlQn.Key} {courseLvlQn.Value.courseName} {courseLvlQn.Value.level}"); if (/*courseLvlQn.Value.userName == userName &&*/ courseLvlQn.Value.courseName == courseName) { if (courseLvlQn.Value.level == lvlNo) { chk = true; } } } }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(500).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("check level exist elapsed milliseconds: {0}" + sec); return(chk); }
///<summary> ///Creating course in database ///</summary> public async Task PostingCourse(Course course, string courseName) { DatabaseQAHandler.PostCourse(course, courseName, () => { }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Creating Course Elapsed milliseconds: {0}" + sec); }
///<summary> ///Creating stud in Database ///</summary> ///<param name = "studName">Student's username</param> public async Task PostingStud(string studName) { (currentCourse.students).Add(studName); DatabaseQAHandler.PutCourse(courseName, currentCourse, () => { }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Enroll Student Elapsed milliseconds: {0}" + sec); }
///<summary> ///Creating question in Database ///</summary> ///<param name = "qn">Question Input</param> ///<param name = "ans">Answer Input</param> public async Task PostingQn(string qn, string ans) { int intAns = int.Parse(ans, System.Globalization.NumberStyles.Integer); (courseLvlQnCreate.qns).Add(qn); (courseLvlQnCreate.ans).Add(intAns); DatabaseQAHandler.PutCourseLvlQn(key, courseLvlQnCreate, () => { }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Creating Qn Elapsed milliseconds: {0}" + sec); }
///<summary> ///Deleting stud in Database ///</summary> public async void DeleteStud() { loader.SetActive(true); (currentCourse.students).RemoveAt(delName); DatabaseQAHandler.PutCourse(courseName, currentCourse, () => { }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Delete Stud Elapsed milliseconds: {0}" + sec); await Read(); loader.SetActive(false); messageBox.SetActive(true); messageBox.transform.GetChild(1).GetComponent <Text>().text = "Unenroll successfully."; }
///<summary> ///Create course buttons ///</summary> public async Task Read() { Debug.Log("ITEMmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"); int count = itemParent.transform.childCount; Debug.Log("IN ITEMPARENT"); if (count != 0) { for (int i = 0; i < count; i++) { Debug.Log("itemparent"); Destroy(itemParent.transform.GetChild(i).gameObject); } } Debug.Log("ITEM 2"); DatabaseQAHandler.GetCourses(courses => { foreach (var course in courses) { Debug.Log($"{course.Key} {course.Value.userName}"); if (course.Value.userName == userName) { GameObject tmp_btn = Instantiate(item, itemParent.transform); tmp_btn.name = course.Key; Debug.Log("item name: " + tmp_btn.name); tmp_btn.transform.GetChild(1).GetComponent <Text>().text = course.Key; } } }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Read elapsed milliseconds: {0}" + sec); }
///<summary> ///Creating buttons for levels ///</summary> public async Task Read() { Debug.Log("READ "); int count = itemParent.transform.childCount; if (count != null) { for (int i = 0; i < count; i++) { Debug.Log("itemparent"); Destroy(itemParent.transform.GetChild(i).gameObject); } } //Retrieve Courses Created by the Teacher DatabaseQAHandler.GetCourseLvlQns(courseLvlQns => { foreach (var courseLvlQn in courseLvlQns) { Debug.Log($"{courseLvlQn.Key} {courseLvlQn.Value.courseName} {courseLvlQn.Value.level}"); if (courseLvlQn.Value.courseName == courseName)//&& courseLvlQn.Value.userName == userName) { GameObject tmp_btn = Instantiate(item, itemParent.transform); tmp_btn.name = courseLvlQn.Key; Debug.Log("item name: " + tmp_btn.name); Debug.Log("lvl name: " + (courseLvlQn.Value.level).ToString()); tmp_btn.transform.GetChild(1).GetComponent <Text>().text = (courseLvlQn.Value.level).ToString(); } } }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Read elapsed milliseconds: {0}" + sec); }
///<summary> ///Check if the course already exist ///</summary> public async Task <bool> CheckCourseExist(string courseName) { chk = false; Debug.Log("line140:" + courseName + "!"); DatabaseQAHandler.GetCourse(courseName, course => { chk = true; Debug.Log("chCourseExist1" + chk); }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(2000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("check course exist elapsed milliseconds: {0}" + sec); locks = false; return(chk); }
///<summary> ///Update question in Database ///</summary> ///<param name = "qn">Question Input</param> ///<param name = "ans">Answer Input</param> public async Task UpdateQn(string qn, string ans) { loader.SetActive(true); courseLvlQnCreate.qns[editName] = qn; courseLvlQnCreate.ans[editName] = int.Parse(ans, System.Globalization.NumberStyles.Integer); DatabaseQAHandler.PutCourseLvlQn(key, courseLvlQnCreate, () => { }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Updating Qn Elapsed milliseconds: {0}" + sec); await Read(); loader.SetActive(false); messageBox.SetActive(true); messageBox.transform.GetChild(1).GetComponent <Text>().text = "Updated successfully."; }
///<summary> ///Delete course in database ///</summary> public async void DeleteCourseLvl() { loader.SetActive(true); Debug.Log("DELETE name: " + key); DatabaseQAHandler.DeleteCourseLvlQn(key, () => { }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Delete elapsed milliseconds: {0}" + sec); await Read(); loader.SetActive(false); messageBox.SetActive(true); messageBox.transform.GetChild(1).GetComponent <Text>().text = "Deleted successfully."; key = null; }
///<summary> ///Create rows showing the list of enrolled students ///</summary> public async Task Read() { int count = itemParent.transform.childCount; if (count != null) { for (int i = 0; i < count; i++) { Debug.Log("itemparent"); Destroy(itemParent.transform.GetChild(i).gameObject); } } DatabaseQAHandler.GetCourse(courseName, course => { currentCourse = new Course(userName, course.students); int number = 1; for (int i = 0; i < (course.students).Count; i++) // Loop through List { Debug.Log("STUDENT[I]" + course.students[i]); GameObject tmp_item = Instantiate(item, itemParent.transform); tmp_item.name = i.ToString(); Debug.Log("here item name: " + tmp_item.name); tmp_item.transform.GetChild(0).GetComponent <Text>().text = number.ToString(); tmp_item.transform.GetChild(1).GetComponent <Text>().text = course.students[i]; number++; } }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Read elapsed milliseconds: {0}" + sec); }