public static GameBoard Play(Student student) { List <Courses> courses; MongoClientConn database = new MongoClientConn("Courses"); //Create an instance of our DB courses = database.GetAll <Courses>("Courses"); Random rand = new Random(); Courses course = courses[rand.Next(0, courses.Count)]; List <Trivia> questions = new List <Trivia>(); for (int i = 0; i < courses.Count; i++) { if (String.Equals(courses[i].CourseName, course.CourseName, StringComparison.Ordinal)) { Console.WriteLine("Question added: " + courses[i].courseQuestions); questions.Add(courses[i].courseQuestions); } } GameBoard game = new GameBoard(1, course, questions, student) { Dock = DockStyle.Fill, TopLevel = false, TopMost = true }; game.FormBorderStyle = FormBorderStyle.None; return(game); }
public static void LoadHelper(CourseGrid courseGrid) { MongoClientConn database = new MongoClientConn("Courses"); //Create an instance of our DB courseGrid.courses = database.GetAll <Courses>("Courses"); //Grab all the courses from the DB List <string> duplicateList = new List <string>(); if (courseGrid.courses != null) { for (int i = 0; i < courseGrid.courses.Count; i++) { Console.WriteLine(courseGrid.courses[i].CourseName); if (duplicateList.Contains(courseGrid.courses[i].CourseName)) { Console.WriteLine("Preventing Duplicates"); } else { var courseName = new string[] { courseGrid.courses[i].CourseName }; var lvi = new ListViewItem(courseName); duplicateList.Add(courseGrid.courses[i].CourseName); lvi.Tag = courseGrid.courses[i]; lvi.Checked = false; courseGrid.listViewCourses.Items.Add(lvi); } } } duplicateList.Clear(); courseGrid.Controls.Add(courseGrid.listViewCourses); }
private void AddTrivia_Load(object sender, EventArgs e) { MongoClientConn database = new MongoClientConn("Courses"); List <Courses> courses = database.GetAll <Courses>("Courses"); for (int i = 0; i < courses.Count(); i++) { if (CoursesList.Items.Contains(courses[i].CourseName)) { Console.WriteLine("Preventing duplicates. "); } else { CoursesList.Items.Add(courses[i].CourseName); } } }