예제 #1
0
        /// <summary>
        /// This method gets the Students data from the DB
        /// </summary>
        private void GetStudentsDetails()
        {
            int StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

            // Connect  to Entity FrameWork
            using (ControlsoContext db = new ControlsoContext())
            {
                //Query the Students Table using EF and LINQ
                var Students = (from allStudents in db.Students
                                where allStudents.StudentID == StudentID
                                select allStudents);
                // bind the result to the Student GridView
                StudentGridView.DataSource = Students.ToList();
                StudentGridView.DataBind();

                //Query the Course Table using EF and LINQ
                var CoursesDetails = (from allCourse in db.Courses
                                      join enrolment in db.Enrollments
                                      on allCourse.CourseID equals enrolment.CourseID
                                      where enrolment.StudentID == StudentID
                                      select new { CourseID = allCourse.CourseID, Title = allCourse.Title, Grade = enrolment.Grade, Credit = allCourse.Credits });
                // bind the result to the Course GridView
                StudentCourseView.DataSource = CoursesDetails.ToList();

                StudentCourseView.DataBind();
            }
        }
예제 #2
0
        protected void CourseDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // Store Which row need to be deleted
            int selectedRow = e.RowIndex;

            // get the seleceted Enrollment Id
            int EnrollmentID = Convert.ToInt32(CourseDetails.DataKeys[selectedRow].Values["EnrollmentID"]);

            using (ControlsoContext db = new ControlsoContext())
            {
                var deleteStudent = (from delStudent in db.Enrollments
                                     where delStudent.EnrollmentID == EnrollmentID
                                     select delStudent);
                // Remove Student from Enrolmented course
                foreach (var item in deleteStudent)
                {
                    db.Enrollments.Remove(item);
                }

                db.SaveChanges();

                // Refresh the Grid
                this.GetStudents();
            }
        }
예제 #3
0
 /// <summary>
 /// This method gets the Students data from the DB
 /// </summary>
 private void GetStudents()
 {
     // Connect  to Entity FrameWork
     using (ControlsoContext db = new ControlsoContext())
     {
         //Query the Students Table using EF and LINQ
         var Students = (from allStudents in db.Students
                         select allStudents);
         // bind the result to the Student GridView
         StudentGridView.DataSource = Students.ToList();
         StudentGridView.DataBind();
     }
 }
예제 #4
0
        private void GetStudents()
        {
            int CourseID = Convert.ToInt32(Request.QueryString["CourseID"]);

            //
            using (ControlsoContext db = new ControlsoContext())
            {
                // query the Student table using EF and LINQ
                var Students = (from allStudents in db.Students
                                join enrollment in db.Enrollments
                                on allStudents.StudentID equals enrollment.StudentID
                                where enrollment.CourseID == CourseID
                                select new { LastName = allStudents.LastName, FirstMidName = allStudents.FirstMidName, EnrollmentID = enrollment.EnrollmentID });
                CourseDetails.DataSource = Students.ToList();
                CourseDetails.DataBind();
            }
        }
예제 #5
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            //use EF to conect to the server
            using (ControlsoContext db = new ControlsoContext())
            {
                //use the student model to create a new students object and
                // save a new record
                Enrollment addStudent = new Enrollment();

                int EnrollmentID = 0;

                if (Request.QueryString.Count > 0)//our URL has a StudentID in it
                {
                    // get the id from the URL

                    /*StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);
                     * //get the Current  student  from EF bd
                     * newStudent = (from student in db.Students
                     *            where student.StudentID == StudentID
                     *            select student).FirstOrDefault();*/
                }
                // add form data th the  new student record
                addStudent.CourseID  = Convert.ToInt32(CourseIDTextBox.Text);
                addStudent.StudentID = Convert.ToInt32(StudentIDTextBox.Text);
                addStudent.Grade     = Convert.ToInt32(GradeTextBox.Text);


                //use  LINQ to ADO.NET to add / insert students into the db
                if (EnrollmentID == 0)
                {
                    db.Enrollments.Add(addStudent);
                }

                //save our changes -also updates and inserts
                db.SaveChanges();

                // Redirect back to the update Students page
                Response.Redirect("Default.aspx");
            }
        }
예제 #6
0
        protected void GetStudent()
        {
            //populated the form with existing data from db
            int StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

            //Connect to the EF DB
            using (ControlsoContext db = new ControlsoContext())
            {
                // populate a student object  instance with the studentID
                // from the url parameter
                Student updateStudent = (from student in db.Students
                                         where student.StudentID == StudentID
                                         select student).FirstOrDefault();
                // map the student properties to the form control
                if (updateStudent != null)
                {
                    LastNameTextBox.Text       = updateStudent.LastName;
                    FirstNameTextbox.Text      = updateStudent.FirstMidName;
                    EnrollmentDateTextbox.Text = updateStudent.EnrollmentDate.ToString("yyyy-MM-dd");
                }
            }
        }