Exemplo n.º 1
0
        public void DeleteStudentsPerCourses(STUDENT_PER_COURSE studentPerCourse, DataClasses1DataContext db)
        {
            STUDENT  sTudent  = new STUDENT();
            Student  student  = new Student();
            Course   course   = new Course();
            Check_ID check_ID = new Check_ID();
            var      listTotalNumbersOfCourses = new List <int>();

            Console.WriteLine("\n\n\t" + "DELETE STUDENTS PER COURSES" +
                              "\n\t----------------------------");


            Console.WriteLine("\t" + "For Dalete one only course press --> {1}");
            Console.WriteLine("\t" + "For Delete all courses prees     --> {2}");
            Console.Write("\t" + "Give a choise between    v  -->  {1 - 2}: ");
            string selection = Console.ReadLine();
            int    choice;

            while (!int.TryParse(selection, out choice) || string.IsNullOrEmpty(selection) || choice < 1 || choice > 2)
            {
                Console.Write("\n\t" + "Give choice again Only Integer between {1 - 2}!!!: ");
                selection = Console.ReadLine();
            }

            int studentID = check_ID.GetTrueStudentIDWhoHaveCourses(student, db);

            if (choice == 1)
            {
                int courseID = course.GetTrueCourseIDForCreate(check_ID, db);
                studentPerCourse            = db.STUDENT_PER_COURSEs.Single(i => i.STUDENT_ID == studentID && i.COURSE_ID == courseID);
                studentPerCourse.STUDENT_ID = studentID;
                studentPerCourse.COURSE_ID  = courseID;
                db.STUDENT_PER_COURSEs.DeleteOnSubmit(studentPerCourse);
                db.SubmitChanges();
            }
            else
            {
                listTotalNumbersOfCourses = GetListTotalNumbersOfCourses(db, studentID);
                int count = 1;

                while (count <= listTotalNumbersOfCourses.Count())
                {
                    foreach (int i in listTotalNumbersOfCourses)
                    {
                        studentPerCourse            = db.STUDENT_PER_COURSEs.Single(j => j.STUDENT_ID == studentID && j.COURSE_ID == i);
                        studentPerCourse.STUDENT_ID = studentID;
                        studentPerCourse.COURSE_ID  = i;
                        db.STUDENT_PER_COURSEs.DeleteOnSubmit(studentPerCourse);
                        db.SubmitChanges();
                        count += 1;
                    }
                }
            }
            Console.WriteLine("\n\tDeleted Succesfully!!!");
        }
Exemplo n.º 2
0
        public void MenuStudentPerCourse(DataClasses1DataContext db)
        {
            STUDENT_PER_COURSE studentPerCourse = new STUDENT_PER_COURSE();
            Student            student          = new Student();
            Check_ID           check_ID         = new Check_ID();

            string stringChoice;

            Console.WriteLine("\n\tSTUDENT PER COURSE MENU\n\t" + "-----------------------");
            Console.WriteLine("\tCreate STUDENT PER COURSE press     --->  {1}");
            Console.WriteLine("\tRead STUDENT PER COURSE press       --->  {2}");
            Console.WriteLine("\tUpdate STUDENT PER COURSE press     --->  {3}");
            Console.WriteLine("\tDelete STUDENT PER COURSE press     --->  {4}");
            Console.Write("\tEnter a choice between --->           {1 - 4}: ");
            stringChoice = Console.ReadLine();
            Console.WriteLine();
            int outChoice;

            while (!int.TryParse(stringChoice, out outChoice) || outChoice < 1 || outChoice > 4)
            {
                Console.WriteLine("\n\tThe choice should be Only integer between {1- 4}!!!");
                Console.Write("\tEnter a new choice: ");
                stringChoice = Console.ReadLine();
            }
            int choice = outChoice;

            switch (choice)
            {
            case (int)SelectionStudentPerCourse.create:
                CreateStudentsPerCourses(studentPerCourse, db);
                break;

            case (int)SelectionStudentPerCourse.read:
                int studentID = check_ID.GetTrueStudentIDWhoHaveCourses(student, db);
                ReadStudentsPerCourses(db, studentID);
                break;

            case (int)SelectionStudentPerCourse.update:
                UpdateStudentsPerCourses(studentPerCourse, db);
                break;

            case (int)SelectionStudentPerCourse.delete:
                DeleteStudentsPerCourses(studentPerCourse, db);
                break;
            }
        }
Exemplo n.º 3
0
        public void UpdateStudentsPerCourses(STUDENT_PER_COURSE studentPerCourse, DataClasses1DataContext db)
        {
            STUDENT  sTudent  = new STUDENT();
            Student  student  = new Student();
            Check_ID check_ID = new Check_ID();

            int studentID = check_ID.GetTrueStudentIDWhoHaveCourses(student, db);

            Console.WriteLine("\n\n\t" + "UPATE STUDENTS PER COURSES" +
                              "\n\t---------------------------");

            sTudent = student.UpdateStudent(db, sTudent, studentID);
            int courseID = GetCourseIdFromStudent(db, sTudent.STUDENT_ID);

            studentPerCourse.STUDENT_ID = sTudent.STUDENT_ID;
            studentPerCourse.COURSE_ID  = courseID;
            db.SubmitChanges();
            Console.WriteLine("\n\tStudents Per Courses was successfully enrolled!!!");
        }