private static void DeleteAStudentById() { using (var db = new SchoolEntities()) { Console.WriteLine("You can delete a student by student Id"); var students = db.StudentGrade.Include(s => s.Person); foreach (var s in students) { Console.WriteLine($" StudentId: {s.StudentID}, student name {s.Person.FirstName} {s.Person.LastName}"); } int studentId = int.Parse(Console.ReadLine()); var sg = db.StudentGrade.Where(s => s.StudentID == studentId); foreach (var s in sg) { db.StudentGrade.Remove(s); } var pp = db.Person.FirstOrDefault(p => p.PersonID == studentId); db.Person.Remove(pp); db.SaveChanges(); } }
private static void CreateCourse() { using (var db = new SchoolEntities()) { Console.WriteLine("Please type a course name"); string cTitle = Console.ReadLine(); Console.WriteLine("Please type Department Id"); foreach (var department in db.Department) { Console.WriteLine($"{department.Name}: {department.DepartmentID}"); } int dId = int.Parse(Console.ReadLine()); string dName = db.Department.FirstOrDefault(n => n.DepartmentID == dId).Name; var c = new Course(); c.Title = cTitle; c.DepartmentID = dId; db.Course.Add(c); db.SaveChanges(); Console.WriteLine($"Course title: {c.Title}, the Department is {dName}"); Console.ReadLine(); } }
private static void CreateInstructor() { using (var db = new SchoolEntities()) { Console.WriteLine("Please type Course Instructor's first name"); string pFirstName = Console.ReadLine(); Console.WriteLine("Please type Course Instructor's last name"); string pLastName = Console.ReadLine(); Console.WriteLine("Please type Course title"); string cTitle = Console.ReadLine(); Console.WriteLine("Please type Department Id"); foreach (var department in db.Department) { Console.WriteLine($"{department.Name}: {department.DepartmentID}"); } int dId = int.Parse(Console.ReadLine()); var p = new Person(); p.FirstName = pFirstName; p.LastName = pLastName; var c = new Course(); c.Title = cTitle; c.DepartmentID = dId; db.Person.Add(p); db.Course.Add(c); db.SaveChanges(); var ci = new CourseInstructor(); ci.CourseID = c.CourseID; ci.PersonID = p.PersonID; db.CourseInstructor.Add(ci); Console.WriteLine($"FirstName: {p.FirstName}, Course title: {c.Title}"); Console.ReadLine(); } }
private static void CreateStudent() { using (var db = new SchoolEntities()) { Console.WriteLine("Please type Student's first name"); string sFirstName = Console.ReadLine(); Console.WriteLine("Please type Student's last name"); string sLastName = Console.ReadLine(); Console.WriteLine("Please type Course title for this student"); string cTitle = Console.ReadLine(); Console.WriteLine("Please type Department Id"); foreach (var department in db.Department) { Console.WriteLine($"{department.Name}: {department.DepartmentID}"); } int dId = int.Parse(Console.ReadLine()); var p = new Person(); p.FirstName = sFirstName; p.LastName = sLastName; var c = new Course(); c.Title = cTitle; c.DepartmentID = dId; db.Person.Add(p); db.Course.Add(c); db.SaveChanges(); var sg = new StudentGrade(); sg.CourseID = c.CourseID; sg.StudentID = p.PersonID; db.StudentGrade.Add(sg); Console.WriteLine($"FirstName: {p.FirstName}, Last Name: {p.LastName}, Course title: {c.Title}"); Console.ReadLine(); } }
private static void DeleteACourseById() { using (var db = new SchoolEntities()) { Console.WriteLine("You can delete a course by couse Id"); var coursess = db.Course.Include(c => c.OnlineCourse) .Include(olc => olc.CourseID) .Include(osc => osc.CourseID) .Include(cii => cii.CourseID) .Include(sg => sg.CourseID); foreach (var c in coursess) { Console.WriteLine($" CourseId: {c.CourseID}, Course Title {c.Title}"); } int courseId = int.Parse(Console.ReadLine()); var OnsiteCourse = db.OnsiteCourse.FirstOrDefault(os => os.CourseID == courseId); db.OnsiteCourse.Remove(OnsiteCourse); var onlinecourse = db.OnlineCourse.FirstOrDefault(olc => olc.CourseID == courseId); db.OnlineCourse.Remove(onlinecourse); var courseInstructor = db.CourseInstructor.First(ci => ci.CourseID == courseId); db.CourseInstructor.Remove(courseInstructor); var studentGrade = db.StudentGrade.FirstOrDefault(sg => sg.CourseID == courseId); db.StudentGrade.Remove(studentGrade); var courses = db.Course.Where(c => c.CourseID == courseId); foreach (var c in courses) { db.Course.Remove(c); } db.SaveChanges(); } }