private void submitButton_Click(object sender, RoutedEventArgs e) { if ((string)durationTimeMenu.Tag == "true" && (string)startTimeMenu.Tag == "true") { db.Appointments.Load(); db.CurrentUsers.Load(); TutoringDB.Appointment tempAppointment = new TutoringDB.Appointment(); tempAppointment.Date = (DateTime)dateDatePicker.SelectedDate; tempAppointment.Time = timeSelected.TimeOfDay; tempAppointment.Id = db.Appointments.Count(); tempAppointment.Duration = timeSpan.TimeOfDay; db.Appointments.Add(tempAppointment); db.Tutors.Load(); db.TutorTuteeCourseAppointments.Load(); TutoringDB.TutorTuteeCourseAppointment joiner = new TutoringDB.TutorTuteeCourseAppointment(); joiner.AppointmentId = tempAppointment.Id; TutoringDB.Tutee tutee = db.Tutees.Where(i => i.Username == db.CurrentUsers.FirstOrDefault().UserName).First(); joiner.TuteeId = tutee.Id; joiner.Id = db.TutorTuteeCourseAppointments.Count(); joiner.Cours = courseComboBox.SelectedItem as TutoringDB.Cours; joiner.Tutor = tutorNameComboBox.SelectedItem as TutoringDB.Tutor; db.TutorTuteeCourseAppointments.Add(joiner); db.SaveChanges(); this.Close(); } else { MessageBox.Show("All Fields Must be Filled to Schedule Appointment"); } }
private void Apply_Click(object sender, RoutedEventArgs e) { db.CurrentUsers.Load(); db.TutorCourses.Load(); db.Tutees.Load(); db.Tutors.Load(); db.Courses.Load(); db.TutorConfirmationRequests.Load(); TutoringDB.Tutee temp = new TutoringDB.Tutee(); TutoringDB.Tutor temp2 = new TutoringDB.Tutor(); TutoringDB.Cours tempcs = new TutoringDB.Cours(); TutoringDB.TutorConfirmationRequest temptcs = new TutoringDB.TutorConfirmationRequest(); if (db.CurrentUsers.FirstOrDefault().Type == "tutee") { foreach (var tte in db.Tutees) { if (db.CurrentUsers.FirstOrDefault().UserName == tte.Username) { temp = tte; } } temp2.FirstName = temp.FirstName; temp2.LastName = temp.LastName; temp2.Password = temp.Password; temp2.UserName = temp.Username; temp2.Year = temp.Year; temp2.Email = temp.Email; //temp2.Id = db.Tutors.Count(); //K:LWEKFN:OINF:EWIOLFNSMDNF:OILEKNF:SOIDLKFNEOIL?JFEWFDSFS db.Tutors.Add(temp2); //db.Tutees.Remove(temp); //FKLJFEPLDKSFNPNEIKNELFPDIMOS:LDKFN:OEIJS db.SaveChanges(); } foreach (var tut in db.Tutors) { if (db.CurrentUsers.FirstOrDefault().UserName == tut.UserName) { temp2 = tut; } } foreach (var cs in db.Courses) { if (cs.CourseName == CourseList.SelectedItem.ToString()) { tempcs = cs; temptcs.Cours = tempcs; temptcs.Tutor = temp2; } } db.TutorConfirmationRequests.Add(temptcs); db.SaveChanges(); this.Close(); }
private void submitButton_Click(object sender, RoutedEventArgs e) { if ((string)durationTimeMenu.Tag == "true" && (string)startTimeMenu.Tag == "true") { db.BusyTimes.Load(); db.CurrentUsers.Load(); TutoringDB.BusyTime tempBusyTime = new TutoringDB.BusyTime(); tempBusyTime.Date = (DateTime)dateDatePicker.SelectedDate; tempBusyTime.Time = timeSelected.TimeOfDay; tempBusyTime.Id = db.BusyTimes.Count(); tempBusyTime.Duration = timeSpan.TimeOfDay; db.BusyTimes.Add(tempBusyTime); if (db.CurrentUsers.First().Type == "tutee") { db.Tutees.Load(); db.TuteeBusyTimes.Load(); TutoringDB.TuteeBusyTime joiner = new TutoringDB.TuteeBusyTime(); joiner.BusyTimeId = tempBusyTime.Id; TutoringDB.Tutee tutee = db.Tutees.Where(i => i.Username == db.CurrentUsers.FirstOrDefault().UserName).First(); joiner.TuteeId = tutee.Id; joiner.Id = db.TuteeBusyTimes.Count(); db.TuteeBusyTimes.Add(joiner); } else { db.TutorBusyTimes.Load(); db.Tutors.Load(); TutoringDB.TutorBusyTime joiner = new TutoringDB.TutorBusyTime(); joiner.BusyTimesId = tempBusyTime.Id; TutoringDB.Tutor tutor = db.Tutors.Where(i => i.UserName == db.CurrentUsers.FirstOrDefault().UserName).First(); joiner.TutorId = tutor.Id; joiner.Id = db.TutorBusyTimes.Count(); db.TutorBusyTimes.Add(joiner); } db.SaveChanges(); this.Close(); } else { MessageBox.Show("All Fields Must be Filled to Add Busy Time"); } }
private void addButton_Click(object sender, RoutedEventArgs e) { TutoringDB.TutorDatabaseEntities db = new TutoringDB.TutorDatabaseEntities(); db.Tutees.Load(); db.Tutors.Load(); db.Faculties.Load(); int numTutees = db.Tutees.Count(); //Error Checking if (firstNameTextBox.Text != "" && lastNameTextBox.Text != "" && usernameTextBox.Text != "" && passwordTextBox.Text != "" && (yearTextBox.Text == "1" || yearTextBox.Text == "2" || yearTextBox.Text == "3" || yearTextBox.Text == "4") && emailTextBox.Text != "" ) { TutoringDB.Tutee temp = new TutoringDB.Tutee(); temp.FirstName = firstNameTextBox.Text; temp.LastName = lastNameTextBox.Text; temp.Username = usernameTextBox.Text; temp.Password = passwordTextBox.Text; temp.Year = Convert.ToInt32(yearTextBox.Text); temp.Email = emailTextBox.Text; db.Tutees.Add(temp); db.SaveChanges(); this.Close(); Label1.Text = ""; } else { Label1.Text = "Completely fill out form"; } }
private void fillTutorsTutees_Click(object sender, EventArgs e) { TutoringDB.TutorDatabaseEntities db = new TutoringDB.TutorDatabaseEntities(); db.Tutors.Load(); db.Tutees.Load(); db.TutorCourses.Load(); //Clear database first foreach (TutoringDB.Tutor t in db.Tutors) { db.Tutors.Remove(t); } foreach (TutoringDB.Tutee f in db.Tutees) { db.Tutees.Remove(f); } foreach (TutoringDB.TutorCourse tc in db.TutorCourses) { db.TutorCourses.Remove(tc); } db.SaveChanges(); TutoringDB.Tutor tempTutor = new TutoringDB.Tutor(); TutoringDB.Tutee tempTutee = new TutoringDB.Tutee(); //Fill Tutors foreach (string line in File.ReadLines(@"fakeTutors.csv")) { db.Tutors.Load(); db.Tutees.Load(); db.TutorCourses.Load(); var split = line.Split('|'); tempTutor.FirstName = split[0]; tempTutor.LastName = split[1]; tempTutor.UserName = split[2]; tempTutor.Password = split[3]; tempTutor.Email = split[4]; Random year = new Random(); tempTutor.Year = year.Next(1, 4); db.Tutors.Add(tempTutor); //Randomly matches tutors with courses Random rnd = new Random(); int limit = rnd.Next(4); db.SaveChanges(); db.Courses.Load(); //var courselist = db.Courses.Local; //for (int i = 0; i< limit; i++) //{ // int max = db.Courses.Count(); // tempTutorCourse.Cours = courselist[rnd.Next(0,max)]; // tempTutorCourse.TutorId = tempTutor.Id+1; // db.TutorCourses.Add(tempTutorCourse); //} //db.SaveChanges(); } //Fill Tutees foreach (string line in File.ReadLines(@"fakeTutees.csv")) { db.Tutors.Load(); db.Tutees.Load(); db.TutorCourses.Load(); var split = line.Split('|'); tempTutee.FirstName = split[0]; tempTutee.LastName = split[1]; tempTutee.Username = split[2]; tempTutee.Password = split[3]; tempTutee.Email = split[4]; Random year = new Random(); tempTutee.Year = year.Next(1, 4); db.Tutees.Add(tempTutee); db.SaveChanges(); } List <TutoringDB.TutorCourse> tcList = new List <TutoringDB.TutorCourse>(); db.Courses.Load(); db.Tutors.Load(); var tutorlist = db.Tutors.Local.ToList(); var courselist = db.Courses.Local.ToList(); int index = 0; foreach (TutoringDB.Cours c in courselist) { Random rnd = new Random(); int lim = rnd.Next(2, 5); for (int i = 0; i < lim; i++) { TutoringDB.TutorCourse tempTutorCourse = new TutoringDB.TutorCourse(); tempTutorCourse.Cours = c; tempTutorCourse.Tutor = tutorlist[index % tutorlist.Count()]; index++; tcList.Add(tempTutorCourse); } } for (int i = 0; i < tcList.Count; i++) { db.TutorCourses.Load(); db.TutorCourses.Add(tcList.ElementAt(i)); db.SaveChanges(); } db.SaveChanges(); MessageBox.Show("Successfully Loaded."); }