Ejemplo n.º 1
0
        protected void AddStudentButton_Click(object sender, EventArgs e)
        {
            if (AddStudentTextBox.Text != "")
            {
                using (var context = new GradebookDataEntities())
                {
                    Course course = context.Courses.FirstOrDefault(c => c.CourseNumber == CourseNumberDropDownList.SelectedValue);
                    Student student = context.Students.FirstOrDefault(s => s.Email == AddStudentTextBox.Text);
                    course.Students.Add(student);

                    context.SaveChanges();

                    var l2equery = from s in context.Students where s.Email.Contains(searchStudentsTextBox.Text) select s.Courses;
                    var courses = l2equery.FirstOrDefault();

                    courseGridView.DataSource = courses;
                    courseGridView.DataBind();
                }
            }
            else
            {
                string email = studentGridView.Rows[studentGridView.SelectedIndex].Cells[0].Text.ToString(); ;
                using (var context = new GradebookDataEntities())
                {
                    Course course = context.Courses.FirstOrDefault(c => c.CourseNumber == CourseNumberDropDownList.SelectedValue);
                    Student student = context.Students.FirstOrDefault(s => s.Email == email);
                    course.Students.Add(student);

                    context.SaveChanges();

                    var l2equery = from s in context.Students where s.Email.Contains(searchStudentsTextBox.Text) select s.Courses;
                    var courses = l2equery.FirstOrDefault();

                    courseGridView.DataSource = courses;
                    courseGridView.DataBind();
                }
            }
        }
Ejemplo n.º 2
0
        protected void registerStudentCourseButton_Click(object sender, EventArgs e)
        {
            if(courseID != 0)
                using(var context = new GradebookDataEntities())
                {
                    Course course = context.Courses.FirstOrDefault(c => c.CourseID == courseID);
                    Student student = context.Students.FirstOrDefault(s => s.Email == email);
                    course.Students.Add(student);

                    context.SaveChanges();
                }
            studentCourseGridViewFill();
        }