public static void CreateNewCourseAndAssignToDep() { using (var db = new SchoolEntities()){ Console.WriteLine("Enter the name of the new course"); var courseName = Console.ReadLine();//Title Console.WriteLine("Enter the credits of the course"); var credit = Convert.ToInt32(Console.ReadLine()); //Assign the course to the department Console.WriteLine("Plz select the department ID that you want to assign the course in"); ViewDep(); var depId = Convert.ToInt32(Console.ReadLine()); //Check if the id exits var course = new Course() { Title = courseName, Credits = credit, DepartmentID = depId }; db.Courses.Add(course); db.SaveChanges(); } }
public static void CreateNewStuAndEnroll() { using (var db = new SchoolEntities()){ //Enter student information Console.WriteLine("Plz enter the first name of the student"); var stuFirst = Console.ReadLine(); Console.WriteLine("Plz enter the last name of the student"); var stuLast = Console.ReadLine(); Console.WriteLine("Plz enter the enrollment date of the student"); var stuEnrollDate = Convert.ToDateTime(Console.ReadLine()); var student = new Person() { FirstName = stuFirst, LastName = stuLast, EnrollmentDate = stuEnrollDate }; //Save student changes db.People.Add(student); db.SaveChanges(); //Enroll the student to course Console.WriteLine("Plz select the course name to enroll the student in"); ViewCourse(); var courseName = Console.ReadLine();//Course title //input the grade of the student Console.WriteLine("Plz enter the grade to the student"); var grade = Convert.ToDouble(Console.ReadLine()); var idListCourse = db.Courses.Where(x => x.Title == courseName).Select(y => y.CourseID).ToList(); var idStuList = db.People.Where(x => x.FirstName == stuFirst).Select(y => y.PersonID).ToList(); var sg = new StudentGrade() { CourseID = idListCourse[0], StudentID = idStuList[0], Grade = grade }; db.StudentGrades.Add(sg); db.SaveChanges(); } }
public static void CreateNewInstructorAndAssign() { using (var db = new SchoolEntities()){ //var instructor = new CourseInstructor(); Console.WriteLine("Plz input the first name of the instructor"); var inputFirst = Console.ReadLine(); Console.WriteLine("Plz input the last name of the instructor"); var inputLast = Console.ReadLine(); Console.WriteLine("Plz enter the hire date"); var inputHireDate = Convert.ToDateTime(Console.ReadLine()); var instructor = new Person() { FirstName = inputFirst, LastName = inputLast, HireDate = inputHireDate }; db.People.Add(instructor);//Save new people info db.SaveChanges(); //ASSIGN INSTRUCTOR in courses Console.WriteLine("Plz select the course name to assign the instructor in"); ViewCourse(); var courseName = Console.ReadLine();//Course title var courseIdList = db.Courses.Where(x => x.Title == courseName).Select(y => y.CourseID).ToList(); var personIdList = db.People.Where(x => x.FirstName == inputFirst).Select(y => y.PersonID).ToList(); foreach (var item in personIdList) { Console.WriteLine(item); } //Enter the info of the INSTRUCTOR in Office Assignment Console.WriteLine("Plz enter the location of office assignment"); var location = Console.ReadLine(); OfficeAssignment oa = new OfficeAssignment() { InstructorID = personIdList[0],//The same as the person id which has been created Location = location, }; db.OfficeAssignments.Add(oa); db.SaveChanges(); CourseInstructor c = new CourseInstructor() { CourseID = courseIdList[0], PersonID = personIdList[0] }; db.CourseInstructors.Add(c); db.SaveChanges(); //using (var db = new SchoolEntities()) //{ // foreach (var item in db.Courses) // { // } // db.People.Add(person); // db.SaveChanges(); //} } }