/// <summary>
 /// There are no comments for OfficeAssignment in the schema.
 /// </summary>
 public void AddToOfficeAssignment(OfficeAssignment officeAssignment)
 {
     base.AddObject("OfficeAssignment", officeAssignment);
 }
Beispiel #2
0
        public static void Initialize(SchoolContext context)
        {
            // Look for any students.
            if (context.Students.Any())
            {
                return;   // DB has been seeded
            }

            var alexander = new Student
            {
                FirstMidName   = "Carson",
                LastName       = "Alexander",
                EnrollmentDate = DateTime.Parse("2016-09-01")
            };

            var alonso = new Student
            {
                FirstMidName   = "Meredith",
                LastName       = "Alonso",
                EnrollmentDate = DateTime.Parse("2018-09-01")
            };

            var anand = new Student
            {
                FirstMidName   = "Arturo",
                LastName       = "Anand",
                EnrollmentDate = DateTime.Parse("2019-09-01")
            };

            var barzdukas = new Student
            {
                FirstMidName   = "Gytis",
                LastName       = "Barzdukas",
                EnrollmentDate = DateTime.Parse("2018-09-01")
            };

            var li = new Student
            {
                FirstMidName   = "Yan",
                LastName       = "Li",
                EnrollmentDate = DateTime.Parse("2018-09-01")
            };

            var justice = new Student
            {
                FirstMidName   = "Peggy",
                LastName       = "Justice",
                EnrollmentDate = DateTime.Parse("2017-09-01")
            };

            var norman = new Student
            {
                FirstMidName   = "Laura",
                LastName       = "Norman",
                EnrollmentDate = DateTime.Parse("2019-09-01")
            };

            var olivetto = new Student
            {
                FirstMidName   = "Nino",
                LastName       = "Olivetto",
                EnrollmentDate = DateTime.Parse("2011-09-01")
            };

            var abercrombie = new Instructor
            {
                FirstMidName = "Kim",
                LastName     = "Abercrombie",
                HireDate     = DateTime.Parse("1995-03-11")
            };

            var fakhouri = new Instructor
            {
                FirstMidName = "Fadi",
                LastName     = "Fakhouri",
                HireDate     = DateTime.Parse("2002-07-06")
            };

            var harui = new Instructor
            {
                FirstMidName = "Roger",
                LastName     = "Harui",
                HireDate     = DateTime.Parse("1998-07-01")
            };

            var kapoor = new Instructor
            {
                FirstMidName = "Candace",
                LastName     = "Kapoor",
                HireDate     = DateTime.Parse("2001-01-15")
            };

            var zheng = new Instructor
            {
                FirstMidName = "Roger",
                LastName     = "Zheng",
                HireDate     = DateTime.Parse("2004-02-12")
            };

            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    Instructor = fakhouri,
                    Location   = "Smith 17"
                },
                new OfficeAssignment {
                    Instructor = harui,
                    Location   = "Gowan 27"
                },
                new OfficeAssignment {
                    Instructor = kapoor,
                    Location   = "Thompson 304"
                },
            };

            context.AddRange(officeAssignments);

            var english = new Department
            {
                Name             = "English",
                Budget           = 350000,
                StartDate        = DateTime.Parse("2007-09-01"),
                Administrator    = abercrombie,
                ConcurrencyToken = Guid.NewGuid()
            };

            var mathematics = new Department
            {
                Name             = "Mathematics",
                Budget           = 100000,
                StartDate        = DateTime.Parse("2007-09-01"),
                Administrator    = fakhouri,
                ConcurrencyToken = Guid.NewGuid()
            };

            var engineering = new Department
            {
                Name             = "Engineering",
                Budget           = 350000,
                StartDate        = DateTime.Parse("2007-09-01"),
                Administrator    = harui,
                ConcurrencyToken = Guid.NewGuid()
            };

            var economics = new Department
            {
                Name             = "Economics",
                Budget           = 100000,
                StartDate        = DateTime.Parse("2007-09-01"),
                Administrator    = kapoor,
                ConcurrencyToken = Guid.NewGuid()
            };

            var chemistry = new Course
            {
                CourseID    = 1050,
                Title       = "Chemistry",
                Credits     = 3,
                Department  = engineering,
                Instructors = new List <Instructor> {
                    kapoor, harui
                }
            };

            var microeconomics = new Course
            {
                CourseID    = 4022,
                Title       = "Microeconomics",
                Credits     = 3,
                Department  = economics,
                Instructors = new List <Instructor> {
                    zheng
                }
            };

            var macroeconmics = new Course
            {
                CourseID    = 4041,
                Title       = "Macroeconomics",
                Credits     = 3,
                Department  = economics,
                Instructors = new List <Instructor> {
                    zheng
                }
            };

            var calculus = new Course
            {
                CourseID    = 1045,
                Title       = "Calculus",
                Credits     = 4,
                Department  = mathematics,
                Instructors = new List <Instructor> {
                    fakhouri
                }
            };

            var trigonometry = new Course
            {
                CourseID    = 3141,
                Title       = "Trigonometry",
                Credits     = 4,
                Department  = mathematics,
                Instructors = new List <Instructor> {
                    harui
                }
            };

            var composition = new Course
            {
                CourseID    = 2021,
                Title       = "Composition",
                Credits     = 3,
                Department  = english,
                Instructors = new List <Instructor> {
                    abercrombie
                }
            };

            var literature = new Course
            {
                CourseID    = 2042,
                Title       = "Literature",
                Credits     = 4,
                Department  = english,
                Instructors = new List <Instructor> {
                    abercrombie
                }
            };

            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    Student = alexander,
                    Course  = chemistry,
                    Grade   = Grade.A
                },
                new Enrollment {
                    Student = alexander,
                    Course  = microeconomics,
                    Grade   = Grade.C
                },
                new Enrollment {
                    Student = alexander,
                    Course  = macroeconmics,
                    Grade   = Grade.B
                },
                new Enrollment {
                    Student = alonso,
                    Course  = calculus,
                    Grade   = Grade.B
                },
                new Enrollment {
                    Student = alonso,
                    Course  = trigonometry,
                    Grade   = Grade.B
                },
                new Enrollment {
                    Student = alonso,
                    Course  = composition,
                    Grade   = Grade.B
                },
                new Enrollment {
                    Student = anand,
                    Course  = chemistry,
                },
                new Enrollment {
                    Student = anand,
                    Course  = microeconomics,
                    Grade   = Grade.B
                },
                new Enrollment {
                    Student = barzdukas,
                    Course  = chemistry,
                    Grade   = Grade.B
                },
                new Enrollment {
                    Student = li,
                    Course  = composition,
                    Grade   = Grade.B
                },
                new Enrollment {
                    Student = justice,
                    Course  = literature,
                    Grade   = Grade.B
                }
            };

            context.AddRange(enrollments);
            context.SaveChanges();
        }
Beispiel #3
0
        public static void Initialize(SchoolContext context)
        {
            //context.Database.EnsureCreated();

            // Look for any students.
            if (context.Students.Any())
            {
                return;   // DB has been seeded
            }

            var students = new Student[]
            {
                new Student {
                    FirstMidName = "Carson", LastName = "Alexander", Email = "*****@*****.**",
                    SurveyDate   = DateTime.Parse("2010-09-01")
                },
                new Student {
                    FirstMidName = "Meredith", LastName = "Alonso", Email = "*****@*****.**",
                    SurveyDate   = DateTime.Parse("2012-09-01")
                },
                new Student {
                    FirstMidName = "Arturo", LastName = "Anand", Email = "*****@*****.**",
                    SurveyDate   = DateTime.Parse("2013-09-01")
                },
                new Student {
                    FirstMidName = "Gytis", LastName = "Barzdukas", Email = "*****@*****.**",
                    SurveyDate   = DateTime.Parse("2012-09-01")
                },
                new Student {
                    FirstMidName = "Yan", LastName = "Li", Email = "*****@*****.**",
                    SurveyDate   = DateTime.Parse("2012-09-01")
                },
                new Student {
                    FirstMidName = "Peggy", LastName = "Justice", Email = "*****@*****.**",
                    SurveyDate   = DateTime.Parse("2011-09-01")
                },
                new Student {
                    FirstMidName = "Laura", LastName = "Norman", Email = "*****@*****.**",
                    SurveyDate   = DateTime.Parse("2013-09-01")
                },
                new Student {
                    FirstMidName = "Nino", LastName = "Olivetto", Email = "*****@*****.**",
                    SurveyDate   = DateTime.Parse("2005-09-01")
                }
            };

            foreach (Student u in students)
            {
                context.Students.Add(u);
            }
            context.SaveChanges();

            var instructors = new Instructor[]
            {
                new Instructor {
                    FirstMidName = "Kim", LastName = "Abercrombie", Email = "*****@*****.**",
                    HireDate     = DateTime.Parse("1995-03-11")
                },
                new Instructor {
                    FirstMidName = "Fadi", LastName = "Fakhouri", Email = "*****@*****.**",
                    HireDate     = DateTime.Parse("2002-07-06")
                },
                new Instructor {
                    FirstMidName = "Roger", LastName = "Harui", Email = "*****@*****.**",
                    HireDate     = DateTime.Parse("1998-07-01")
                },
                new Instructor {
                    FirstMidName = "Candace", LastName = "Kapoor", Email = "*****@*****.**",
                    HireDate     = DateTime.Parse("2001-01-15")
                },
                new Instructor {
                    FirstMidName = "Roger", LastName = "Zheng", Email = "*****@*****.**",
                    HireDate     = DateTime.Parse("2004-02-12")
                }
            };

            foreach (Instructor i in instructors)
            {
                context.Instructors.Add(i);
            }
            context.SaveChanges();

            var departments = new Department[]
            {
                new Department {
                    Name         = "English",
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new Department {
                    Name         = "Mathematics",
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new Department {
                    Name         = "Engineering",
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new Department {
                    Name         = "Economics",
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID
                }
            };

            foreach (Department d in departments)
            {
                context.Departments.Add(d);
            }
            context.SaveChanges();

            var courses = new Course[]
            {
                new Course {
                    CourseID     = 1050, Title = "Chemistry", Credits = 3,
                    DepartmentID = departments.Single(u => u.Name == "Engineering").DepartmentID
                },
                new Course {
                    CourseID     = 4022, Title = "Microeconomics", Credits = 3,
                    DepartmentID = departments.Single(u => u.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 4041, Title = "Macroeconomics", Credits = 3,
                    DepartmentID = departments.Single(u => u.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 1045, Title = "Calculus", Credits = 4,
                    DepartmentID = departments.Single(u => u.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 3141, Title = "Trigonometry", Credits = 4,
                    DepartmentID = departments.Single(u => u.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 2021, Title = "Composition", Credits = 3,
                    DepartmentID = departments.Single(u => u.Name == "English").DepartmentID
                },
                new Course {
                    CourseID     = 2042, Title = "Literature", Credits = 4,
                    DepartmentID = departments.Single(u => u.Name == "English").DepartmentID
                },
            };

            foreach (Course c in courses)
            {
                context.Courses.Add(c);
            }
            context.SaveChanges();

            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID,
                    Location     = "Smith 17"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID,
                    Location     = "Gowan 27"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID,
                    Location     = "Thompson 304"
                },
            };

            foreach (OfficeAssignment o in officeAssignments)
            {
                context.OfficeAssignments.Add(o);
            }
            context.SaveChanges();

            var courseInstructors = new CourseAssignment[]
            {
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Calculus").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Composition").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Literature").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
            };

            foreach (CourseAssignment ci in courseInstructors)
            {
                context.CourseAssignments.Add(ci);
            }
            context.SaveChanges();

            var surveys = new Survey[]
            {
                new Survey {
                    StudentID = students.Single(u => u.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                },
                new Survey {
                    StudentID = students.Single(u => u.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                },
                new Survey {
                    StudentID = students.Single(u => u.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                },
                new Survey {
                    StudentID = students.Single(u => u.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Calculus").CourseID,
                },
                new Survey {
                    StudentID = students.Single(u => u.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Trigonometry").CourseID,
                },
                new Survey {
                    StudentID = students.Single(u => u.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                },
                new Survey {
                    StudentID = students.Single(u => u.LastName == "Anand").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID
                },
                new Survey {
                    StudentID = students.Single(u => u.LastName == "Anand").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                },
                new Survey {
                    StudentID = students.Single(u => u.LastName == "Barzdukas").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                },
                new Survey {
                    StudentID = students.Single(u => u.LastName == "Li").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                },
                new Survey {
                    StudentID = students.Single(u => u.LastName == "Justice").ID,
                    CourseID  = courses.Single(c => c.Title == "Literature").CourseID,
                }
            };

            foreach (Survey s in surveys)
            {
                var SurveyInDataBase = context.Surveys.Where(
                    u =>
                    u.Student.ID == s.StudentID &&
                    u.Course.CourseID == s.CourseID).SingleOrDefault();
                if (SurveyInDataBase == null)
                {
                    context.Surveys.Add(s);
                }
            }
            context.SaveChanges();
        }
 public void DeleteOfficeAssignment(OfficeAssignment officeAssignment)
 {
     context.OfficeAssignments.Attach(officeAssignment);
     context.OfficeAssignments.DeleteObject(officeAssignment);
     context.SaveChanges();
 }
 public ActionResult Edit(int id, string lastName, string firstMidName, DateTime hireDate, OfficeAssignment officeAssignment, string[] selectedCourses)
 {
     instructorRepository.Update(id, lastName, firstMidName, hireDate, officeAssignment.Location, selectedCourses?.Select(int.Parse).ToArray());
     return(RedirectToAction("Index"));
 }
Beispiel #6
0
 private Task <int> Persist(OfficeAssignment officeAssignment) =>
 _officeAssignmentRepository.Create(officeAssignment);
        public async Task <ActionResult <OfficeAssignment> > PostOfficeAssignmentAsync(OfficeAssignment officeAssignment)
        {
            await _context.OfficeAssignment.AddAsync(officeAssignment);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (OfficeAssignmentExists(officeAssignment.InstructorId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetOfficeAssignment", new { id = officeAssignment.InstructorId }, officeAssignment));
        }
Beispiel #8
0
 public void DeleteOfficeAssignment(OfficeAssignment officeAssignment)
 {
     context.OfficeAssignments.Remove(officeAssignment);
     context.SaveChanges();
 }
 public async Task<IActionResult> PostOfficeAssignmentAsync(OfficeAssignment assignment)
 {
     await db.OfficeAssignment.AddAsync(assignment);
     await db.SaveChangesAsync();
     return Created($"/api/officeassignments/{assignment.InstructorId}", assignment);
 }
Beispiel #10
0
        public static void Initialize(SchoolContext context)
        {
            //context.Database.EnsureCreated();

            // Look for any students.
            if (context.Student.Any())
            {
                return;   // DB has been seeded
            }

            var students = new Student[]
            {
                new Student {
                    FirstMidName   = "Chase", LastName = "Greenwood",
                    EnrollmentDate = DateTime.Parse("2016-09-01")
                },
                new Student {
                    FirstMidName   = "Spencer", LastName = "Harston",
                    EnrollmentDate = DateTime.Parse("2017-09-01")
                },
                new Student {
                    FirstMidName   = "Mark", LastName = "Haslam",
                    EnrollmentDate = DateTime.Parse("2015-09-01")
                },
                new Student {
                    FirstMidName   = "Dongmin", LastName = "Kim",
                    EnrollmentDate = DateTime.Parse("2015-09-01")
                },
                new Student {
                    FirstMidName   = "Dewey", LastName = "Lakey",
                    EnrollmentDate = DateTime.Parse("2016-09-01")
                },
                new Student {
                    FirstMidName   = "Nicholas", LastName = "Lambert",
                    EnrollmentDate = DateTime.Parse("2015-09-01")
                },
                new Student {
                    FirstMidName   = "Amy", LastName = "Lea",
                    EnrollmentDate = DateTime.Parse("2015-09-01")
                },
                new Student {
                    FirstMidName   = "Andrew", LastName = "Merrell",
                    EnrollmentDate = DateTime.Parse("2015-09-01")
                },
                new Student {
                    FirstMidName   = "Belete", LastName = "Nigusie",
                    EnrollmentDate = DateTime.Parse("2015-09-01")
                },
                new Student {
                    FirstMidName   = "Johnathan", LastName = "Warnes",
                    EnrollmentDate = DateTime.Parse("2016-09-01")
                }
            };

            foreach (Student s in students)
            {
                context.Student.Add(s);
            }
            context.SaveChanges();

            var instructors = new Instructor[]
            {
                new Instructor {
                    FirstMidName = "Richard", LastName = "Fry",
                    HireDate     = DateTime.Parse("2001-03-11")
                },
                new Instructor {
                    FirstMidName = "Brian", LastName = "Rague",
                    HireDate     = DateTime.Parse("2002-07-06")
                },
                new Instructor {
                    FirstMidName = "Spencer", LastName = "Hilton",
                    HireDate     = DateTime.Parse("2008-07-01")
                },
                new Instructor {
                    FirstMidName = "Drew", LastName = "Weidman",
                    HireDate     = DateTime.Parse("2011-01-15")
                },
                new Instructor {
                    FirstMidName = "Linda", LastName = "DuHadaway",
                    HireDate     = DateTime.Parse("2014-02-12")
                }
            };

            foreach (Instructor i in instructors)
            {
                context.Instructor.Add(i);
            }
            context.SaveChanges();

            var departments = new Department[]
            {
                new Department {
                    Name         = "Computer Science", Budget = 350000,
                    StartDate    = DateTime.Parse("2017-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Fry").ID
                },
                new Department {
                    Name         = "Web UX", Budget = 100000,
                    StartDate    = DateTime.Parse("2017-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Hilton").ID
                },
                new Department {
                    Name         = "Engineering", Budget = 350000,
                    StartDate    = DateTime.Parse("2017-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Rague").ID
                },
                new Department {
                    Name         = "Networking", Budget = 100000,
                    StartDate    = DateTime.Parse("2017-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "DuHadaway").ID
                }
            };

            foreach (Department d in departments)
            {
                context.Department.Add(d);
            }
            context.SaveChanges();

            var courses = new Course[]
            {
                new Course {
                    CourseID     = 1030, Title = "Intro to Engineering", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Engineering").DepartmentID
                },
                new Course {
                    CourseID     = 4200, Title = "Wireless Security", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Networking").DepartmentID
                },
                new Course {
                    CourseID     = 4800, Title = "Independent Project", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Computer Science").DepartmentID
                },
                new Course {
                    CourseID     = 2500, Title = "The User Experience", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Web UX").DepartmentID
                },
                new Course {
                    CourseID     = 3100, Title = "Operating Systems", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Computer Science").DepartmentID
                },
                new Course {
                    CourseID     = 2705, Title = "Local Area Networks", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Networking").DepartmentID
                },
                new Course {
                    CourseID     = 1430, Title = "JavaScript", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Web UX").DepartmentID
                },
            };

            foreach (Course c in courses)
            {
                context.Course.Add(c);
            }
            context.SaveChanges();

            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Fry").ID,
                    Location     = "EH 383"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Hilton").ID,
                    Location     = "TE 273"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "DuHadaway").ID,
                    Location     = "TE 304"
                },
            };

            foreach (OfficeAssignment o in officeAssignments)
            {
                context.OfficeAssignment.Add(o);
            }
            context.SaveChanges();

            var courseInstructors = new CourseAssignment[]
            {
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "JavaScript").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Fry").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "JavaScript").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Hilton").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Local Area Networks").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Rague").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "The User Experience").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "DuHadaway").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Operating Systems").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Fry").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Intro to Engineering").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Hilton").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Wireless Security").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Weidman").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Intro to Engineering").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Rague").ID
                },
            };

            foreach (CourseAssignment ci in courseInstructors)
            {
                context.CourseAssignment.Add(ci);
            }
            context.SaveChanges();

            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Greenwood").ID,
                    CourseID  = courses.Single(c => c.Title == "Intro to Engineering").CourseID,
                    Grade     = GradeLetter.A
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Warnes").ID,
                    CourseID  = courses.Single(c => c.Title == "Operating Systems").CourseID,
                    Grade     = GradeLetter.C
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Lakey").ID,
                    CourseID  = courses.Single(c => c.Title == "The User Experience").CourseID,
                    Grade     = GradeLetter.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Lea").ID,
                    CourseID  = courses.Single(c => c.Title == "The User Experience").CourseID,
                    Grade     = GradeLetter.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Kim").ID,
                    CourseID  = courses.Single(c => c.Title == "Wireless Security").CourseID,
                    Grade     = GradeLetter.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Harston").ID,
                    CourseID  = courses.Single(c => c.Title == "Operating Systems").CourseID,
                    Grade     = GradeLetter.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Merrell").ID,
                    CourseID  = courses.Single(c => c.Title == "Independent Project").CourseID
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Lambert").ID,
                    CourseID  = courses.Single(c => c.Title == "JavaScript").CourseID,
                    Grade     = GradeLetter.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Haslam").ID,
                    CourseID  = courses.Single(c => c.Title == "Local Area Networks").CourseID,
                    Grade     = GradeLetter.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Lea").ID,
                    CourseID  = courses.Single(c => c.Title == "JavaScript").CourseID,
                    Grade     = GradeLetter.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Greenwood").ID,
                    CourseID  = courses.Single(c => c.Title == "Independent Project").CourseID,
                    Grade     = GradeLetter.B
                }
            };

            foreach (Enrollment e in enrollments)
            {
                var enrollmentInDataBase = context.Enrollment.Where(
                    s =>
                    s.Student.ID == e.StudentID &&
                    s.Course.CourseID == e.CourseID).SingleOrDefault();
                if (enrollmentInDataBase == null)
                {
                    context.Enrollment.Add(e);
                }
            }
            context.SaveChanges();
        }
Beispiel #11
0
        public static void Initialize(SchoolContext context)
        {
            context.Database.EnsureCreated();

            if (context.Students.Any())
            {
                return;
            }

            var students = new Student[]
            {
                new Student {
                    FirstMidName = "Carson", LastName = "Alexander", EnrollmentDate = DateTime.Parse("2005-09-01")
                },
                new Student {
                    FirstMidName = "Meredith", LastName = "Alonso", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    FirstMidName = "Arturo", LastName = "Anand", EnrollmentDate = DateTime.Parse("2003-09-01")
                },
                new Student {
                    FirstMidName = "Gytis", LastName = "Barzdukas", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    FirstMidName = "Yan", LastName = "Li", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    FirstMidName = "Peggy", LastName = "Justice", EnrollmentDate = DateTime.Parse("2001-09-01")
                },
                new Student {
                    FirstMidName = "Laura", LastName = "Norman", EnrollmentDate = DateTime.Parse("2003-09-01")
                },
                new Student {
                    FirstMidName = "Nino", LastName = "Olivetto", EnrollmentDate = DateTime.Parse("2005-09-01")
                }
            };

            foreach (Student s in students)
            {
                context.Students.Add(s);
            }

            context.SaveChanges();

            var instructors = new Instructor[]
            {
                new Instructor {
                    FirstMidName = "Kim", LastName = "Abercrombie",
                    HireDate     = DateTime.Parse("1995-03-11")
                },
                new Instructor {
                    FirstMidName = "Fadi", LastName = "Fakhouri",
                    HireDate     = DateTime.Parse("2002-07-06")
                },
                new Instructor {
                    FirstMidName = "Roger", LastName = "Harui",
                    HireDate     = DateTime.Parse("1998-07-01")
                },
                new Instructor {
                    FirstMidName = "Candace", LastName = "Kapoor",
                    HireDate     = DateTime.Parse("2001-01-15")
                },
                new Instructor {
                    FirstMidName = "Roger", LastName = "Zheng",
                    HireDate     = DateTime.Parse("2004-02-12")
                }
            };

            foreach (Instructor i in instructors)
            {
                context.Instructors.Add(i);
            }

            context.SaveChanges();

            var departments = new Department[]
            {
                new Department {
                    Name         = "English", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new Department {
                    Name         = "Mathematics", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new Department {
                    Name         = "Engineering", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new Department {
                    Name         = "Economics", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID
                }
            };

            foreach (Department d in departments)
            {
                context.Departments.Add(d);
            }

            context.SaveChanges();

            var courses = new Course[]
            {
                new Course {
                    CourseID = 1050, Title = "Chemistry", Credits = 3
                },
                new Course {
                    CourseID = 4022, Title = "Microeconomics", Credits = 3
                },
                new Course {
                    CourseID = 4041, Title = "Macroeconomics", Credits = 3
                },
                new Course {
                    CourseID = 1045, Title = "Calculus", Credits = 4
                },
                new Course {
                    CourseID = 3141, Title = "Trigonometry", Credits = 4
                },
                new Course {
                    CourseID = 2021, Title = "Composition", Credits = 3
                },
                new Course {
                    CourseID = 2042, Title = "Literature", Credits = 4
                }
            };

            foreach (Course c in courses)
            {
                context.Courses.Add(c);
            }

            context.SaveChanges();

            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID,
                    Location     = "Smith 17"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID,
                    Location     = "Gowan 27"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID,
                    Location     = "Thompson 304"
                },
            };

            var courseInstrucotrs = new CourseAssignment[]
            {
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Calculus").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Composition").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Literature").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
            };

            foreach (CourseAssignment ca in courseInstrucotrs)
            {
                context.CourseAssignments.Add(ca);
            }

            context.SaveChanges();

            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    StudentID = 1, CourseID = 1050, Grade = Grade.A
                },
                new Enrollment {
                    StudentID = 1, CourseID = 4022, Grade = Grade.C
                },
                new Enrollment {
                    StudentID = 1, CourseID = 4041, Grade = Grade.B
                },
                new Enrollment {
                    StudentID = 2, CourseID = 1045, Grade = Grade.B
                },
                new Enrollment {
                    StudentID = 2, CourseID = 3141, Grade = Grade.F
                },
                new Enrollment {
                    StudentID = 2, CourseID = 2021, Grade = Grade.F
                },
                new Enrollment {
                    StudentID = 3, CourseID = 1050
                },
                new Enrollment {
                    StudentID = 4, CourseID = 1050
                },
                new Enrollment {
                    StudentID = 4, CourseID = 4022, Grade = Grade.F
                },
                new Enrollment {
                    StudentID = 5, CourseID = 4041, Grade = Grade.C
                },
                new Enrollment {
                    StudentID = 6, CourseID = 1045
                },
                new Enrollment {
                    StudentID = 7, CourseID = 3141, Grade = Grade.A
                },
            };

            foreach (Enrollment e in enrollments)
            {
                context.Enrollments.Add(e);
            }

            context.SaveChanges();
        }
Beispiel #12
0
        protected override void Seed(ExpensesAPI.Data.AppDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.

            context.Entries.Add(
                new Models.Entry()
            {
                Description = "test",
                IsExpense   = false,
                Value       = 3
            });



            var summerfields = new SummerField[]
            {
                new SummerField {
                    Block     = "Kim", Lot = "Abercrombie",
                    StartDate = DateTime.Parse("1995-03-11")
                },
                new SummerField {
                    Block     = "Fadi", Lot = "Fakhouri",
                    StartDate = DateTime.Parse("2002-07-06")
                },
                new SummerField {
                    Block     = "Roger", Lot = "Harui",
                    StartDate = DateTime.Parse("1998-07-01")
                },
                new SummerField {
                    Block     = "Candace", Lot = "Kapoor",
                    StartDate = DateTime.Parse("2001-01-15")
                },
                new SummerField {
                    Block = "Roger", Lot = "Zheng", StartDate = DateTime.Parse("2004-02-12")
                }
            };



            try
            {
                foreach (SummerField i in summerfields)
                {
                    context.SummerField.Add(i);
                }
                context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"",
                                          ve.PropertyName,
                                          eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName),
                                          ve.ErrorMessage);
                    }
                }
                throw;
            }


            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    OfficeAssignmentId = summerfields.Single(i => i.Lot == "Abercrombie").Id, Location = "Abercrombie 17"
                },
                new OfficeAssignment {
                    OfficeAssignmentId = summerfields.Single(i => i.Lot == "Fakhouri").Id, Location = "Smith 17"
                },
                new OfficeAssignment {
                    OfficeAssignmentId = summerfields.Single(i => i.Lot == "Harui").Id, Location = "Gowan 27"
                },
                new OfficeAssignment {
                    OfficeAssignmentId = summerfields.Single(i => i.Lot == "Kapoor").Id, Location = "Thompson 304"
                },

                new OfficeAssignment {
                    OfficeAssignmentId = summerfields.Single(i => i.Lot == "Zheng").Id, Location = "Zheng House"
                }
            };



            try
            {
                foreach (OfficeAssignment o in officeAssignments)
                {
                    context.OfficeAssignments.Add(o);
                }
                context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"",
                                          ve.PropertyName,
                                          eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName),
                                          ve.ErrorMessage);
                    }
                }
                throw;
            }

            // var students = new Student[] {
            //     new Student { Name = "MArian" },
            //     new Student { Name = "Jerome" },
            //};
            // foreach (Student ia in students)
            // {
            //     context.Students.Add(ia);
            // }
            // context.SaveChanges();
        }
Beispiel #13
0
        public static void Initialize(SchoolContext context)
        {
            //================================================== STUDENTS ============================================//
            // Look for any students.
            if (context.Students.Any())
            {
                return;   // DB has been seeded
            }

            var students = new Student[]
            {
                new Student
                {
                    FirstName      = "Carson",
                    LastName       = "Alexander",
                    Email          = "*****@*****.**",
                    EnrollmentDate = DateTime.Parse("2016-09-01"),
                    Address        = "4 Flanders Court",
                    City           = "Moncton",
                    Province       = "NB",
                    PostalCode     = "E1C 0K6"
                },
                new Student
                {
                    FirstName      = "Meredith",
                    LastName       = "Alonso",
                    Email          = "*****@*****.**",
                    EnrollmentDate = DateTime.Parse("2016-09-01"),
                    Address        = "25 Garden Hill Ave.",
                    City           = "Moncton",
                    Province       = "NB",
                    PostalCode     = "E1C 3E2"
                },
                new Student
                {
                    FirstName      = "Arturo",
                    LastName       = "Anand",
                    Email          = "*****@*****.**",
                    EnrollmentDate = DateTime.Parse("2016-09-01"),
                    Address        = "205 Argyle Street",
                    City           = "Moncton",
                    Province       = "NB",
                    PostalCode     = "E1C 8V2"
                },
                new Student
                {
                    FirstName      = "Gytis",
                    LastName       = "Barzdukas",
                    Email          = "*****@*****.**",
                    EnrollmentDate = DateTime.Parse("2016-09-01"),
                    Address        = "16-33 MacAleese Lane",
                    City           = "Moncton",
                    Province       = "NB",
                    PostalCode     = "E1H 3M1"
                },
                new Student
                {
                    FirstName      = "Yan",
                    LastName       = "Li",
                    Email          = "*****@*****.**",
                    EnrollmentDate = DateTime.Parse("2016-09-01"),
                    Address        = "88 Holland",
                    City           = "Moncton",
                    Province       = "NB",
                    PostalCode     = "E1G 0X1"
                },
                new Student
                {
                    FirstName      = "Peggy",
                    LastName       = "Justice",
                    Email          = "*****@*****.**",
                    EnrollmentDate = DateTime.Parse("2016-09-01"),
                    Address        = "49 Tanya Crescent",
                    City           = "Moncton",
                    Province       = "NB",
                    PostalCode     = "E1E 4V3"
                },
                new Student
                {
                    FirstName      = "Laura",
                    LastName       = "Norman",
                    Email          = "*****@*****.**",
                    EnrollmentDate = DateTime.Parse("2016-09-01"),
                    Address        = "42 Railway Avenue",
                    City           = "Moncton",
                    Province       = "NB",
                    PostalCode     = "E1C 2E1"
                },
                new Student
                {
                    FirstName      = "Nino",
                    LastName       = "Olivetto",
                    Email          = "*****@*****.**",
                    EnrollmentDate = DateTime.Parse("2016-09-01"),
                    Address        = "419 Evergreen Drive",
                    City           = "Moncton",
                    Province       = "NB",
                    PostalCode     = "E1G 5G7"
                }
            };

            foreach (Student s in students)
            {
                context.Students.Add(s);
            }
            context.SaveChanges();

            //================================================== INSTRUCTORS  ============================================//
            var instructors = new Instructor[]
            {
                new Instructor
                {
                    FirstName  = "Marc",
                    LastName   = "Williams",
                    HireDate   = DateTime.Parse("1996-01-31"),
                    Email      = "*****@*****.**",
                    Address    = "819 Front Mountain Road",
                    City       = "Moncton",
                    Province   = "NB",
                    PostalCode = "E1G 3H2"
                },
                new Instructor {
                    FirstName  = "Frank",
                    LastName   = "Bekkering",
                    HireDate   = DateTime.Parse("1997-08-30"),
                    Email      = "*****@*****.**",
                    Address    = "22 Millstone Court",
                    City       = "Ammon",
                    Province   = "NB",
                    PostalCode = "E1G 0W5"
                },
                new Instructor {
                    FirstName  = "Kim",
                    LastName   = "Abercrombie",
                    HireDate   = DateTime.Parse("1995-03-11"),
                    Email      = "*****@*****.**",
                    Address    = "83 Birch Hill",
                    City       = "Ammon",
                    Province   = "NB",
                    PostalCode = "E1G 4R2"
                },
                new Instructor {
                    FirstName  = "Fadi",
                    LastName   = "Fakhouri",
                    HireDate   = DateTime.Parse("2002-07-06"),
                    Email      = "*****@*****.**",
                    Address    = "89 Thorncastle Street",
                    City       = "Moncton",
                    Province   = "NB",
                    PostalCode = "E1G 0S6"
                },
                new Instructor {
                    FirstName  = "Roger",
                    LastName   = "Harui",
                    HireDate   = DateTime.Parse("1998-07-01"),
                    Email      = "*****@*****.**",
                    Address    = "8 Silence Circle",
                    City       = "Moncton",
                    Province   = "NB",
                    PostalCode = "E1A 0A3"
                },
                new Instructor {
                    FirstName  = "Candace",
                    LastName   = "Kapoor",
                    HireDate   = DateTime.Parse("2001-01-15"),
                    Email      = "*****@*****.**",
                    Address    = "2392 Route 106",
                    City       = "Boundary Creek",
                    Province   = "NB",
                    PostalCode = "E1G 4L6"
                },
                new Instructor {
                    FirstName  = "Roger",
                    LastName   = "Zheng",
                    HireDate   = DateTime.Parse("2004-02-12"),
                    Email      = "*****@*****.**",
                    Address    = "4 Flanders Court",
                    City       = "Moncton",
                    Province   = "NB",
                    PostalCode = "E1C 0K6"
                }
            };

            foreach (Instructor i in instructors)
            {
                context.Instructors.Add(i);
            }
            context.SaveChanges();

            //================================================== DEPARTMENTS  ============================================//
            var departments = new Department[]
            {
                new Department {
                    Name         = "English", Budget = 350000, CreatedDate = DateTime.Parse("2017-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new Department {
                    Name         = "Mathematics", Budget = 100000, CreatedDate = DateTime.Parse("2017-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new Department {
                    Name         = "Engineering", Budget = 350000, CreatedDate = DateTime.Parse("2017-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new Department {
                    Name         = "Economics", Budget = 100000, CreatedDate = DateTime.Parse("2017-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID
                }
            };

            foreach (Department d in departments)
            {
                context.Departments.Add(d);
            }
            context.SaveChanges();
            //================================================== COURSES ==============================================//
            var courses = new Course[]
            {
                new Course {
                    CourseID     = 1050, Title = "Chemistry", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Engineering").DepartmentID
                },
                new Course {
                    CourseID     = 4022, Title = "Microeconomics", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 4041, Title = "Macroeconomics", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 1045, Title = "Calculus", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 3141, Title = "Trigonometry", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 2021, Title = "Composition", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
                new Course {
                    CourseID     = 2042, Title = "Literature", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
            };

            foreach (Course c in courses)
            {
                context.Courses.Add(c);
            }
            context.SaveChanges();

            //================================================== OFFICE ASSIGNMENTS ==============================================//
            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID,
                    Location     = "Smith 17"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID,
                    Location     = "Gowan 27"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID,
                    Location     = "Thompson 304"
                },
            };

            foreach (OfficeAssignment o in officeAssignments)
            {
                context.OfficeAssignments.Add(o);
            }
            context.SaveChanges();


            //================================================== COURSE ASSIGNMENTS  ==============================================//
            var courseInstructors = new CourseAssignment[]
            {
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Calculus").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Composition").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Literature").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
            };

            foreach (CourseAssignment ci in courseInstructors)
            {
                context.CourseAssignments.Add(ci);
            }
            context.SaveChanges();



            //================================================== ENROLLMENT  ==============================================//
            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.A
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.C
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Calculus").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Anand").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Anand").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Barzdukas").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Li").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Justice").ID,
                    CourseID  = courses.Single(c => c.Title == "Literature").CourseID,
                    Grade     = Grade.B
                }
            };

            foreach (Enrollment e in enrollments)
            {
                var enrollmentInDataBase = context.Enrollments.Where(
                    s =>
                    s.Student.ID == e.StudentID &&
                    s.Course.CourseID == e.CourseID).SingleOrDefault();
                if (enrollmentInDataBase == null)
                {
                    context.Enrollments.Add(e);
                }
            }
            context.SaveChanges();
        }
Beispiel #14
0
        public static void Initialize(FootballContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.Players.Any())
            {
                return;   // DB has been seeded
            }

            var students = new Player[]
            {
                new Player {
                    FirstMidName = "Carson", LastName = "Alexander", SigningDate = DateTime.Parse("2005-09-01")
                },
                new Player {
                    FirstMidName = "Meredith", LastName = "Alonso", SigningDate = DateTime.Parse("2002-09-01")
                },
                new Player {
                    FirstMidName = "Arturo", LastName = "Anand", SigningDate = DateTime.Parse("2003-09-01")
                },
                new Player {
                    FirstMidName = "Gytis", LastName = "Barzdukas", SigningDate = DateTime.Parse("2002-09-01")
                },
                new Player {
                    FirstMidName = "Yan", LastName = "Li", SigningDate = DateTime.Parse("2002-09-01")
                },
                new Player {
                    FirstMidName = "Peggy", LastName = "Justice", SigningDate = DateTime.Parse("2001-09-01")
                },
                new Player {
                    FirstMidName = "Laura", LastName = "Norman", SigningDate = DateTime.Parse("2003-09-01")
                },
                new Player {
                    FirstMidName = "Nino", LastName = "Olivetto", SigningDate = DateTime.Parse("2005-09-01")
                }
            };

            foreach (Player s in students)
            {
                context.Players.Add(s);
            }
            context.SaveChanges();

            var staffs = new Staff[]
            {
                new Staff {
                    FirstMidName = "Kim", LastName = "Abercrombie",
                    HireDate     = DateTime.Parse("1995-03-11")
                },
                new Staff {
                    FirstMidName = "Fadi", LastName = "Fakhouri",
                    HireDate     = DateTime.Parse("2002-07-06")
                },
                new Staff {
                    FirstMidName = "Roger", LastName = "Harui",
                    HireDate     = DateTime.Parse("1998-07-01")
                },
                new Staff {
                    FirstMidName = "Candace", LastName = "Kapoor",
                    HireDate     = DateTime.Parse("2001-01-15")
                },
                new Staff {
                    FirstMidName = "Roger", LastName = "Zheng",
                    HireDate     = DateTime.Parse("2004-02-12")
                }
            };

            foreach (Staff i in staffs)
            {
                context.Staffs.Add(i);
            }
            context.SaveChanges();

            var departments = new Department[]
            {
                new Department {
                    Name      = "Grass Training Pitch", Budget = 350000,
                    StartDate = DateTime.Parse("2007-09-01"),
                    StaffID   = staffs.Single(i => i.LastName == "Abercrombie").ID
                },
                new Department {
                    Name      = "Artifical Grass Training Pitch", Budget = 100000,
                    StartDate = DateTime.Parse("2007-09-01"),
                    StaffID   = staffs.Single(i => i.LastName == "Fakhouri").ID
                },
                new Department {
                    Name      = "Gym", Budget = 350000,
                    StartDate = DateTime.Parse("2007-09-01"),
                    StaffID   = staffs.Single(i => i.LastName == "Harui").ID
                },
                new Department {
                    Name      = "Stadion", Budget = 100000,
                    StartDate = DateTime.Parse("2007-09-01"),
                    StaffID   = staffs.Single(i => i.LastName == "Kapoor").ID
                },
                new Department {
                    Name      = "Tactics Class", Budget = 200000,
                    StartDate = DateTime.Parse("2009-07-12"),
                    StaffID   = staffs.Single(i => i.LastName == "Zheng").ID
                }
            };

            foreach (Department d in departments)
            {
                context.Departments.Add(d);
            }
            context.SaveChanges();


            var trainings = new Training[]
            {
                new Training {
                    TrainingID = 1050, Title = "Field practice", Credits = 3, DepartmentID = departments.Single(s => s.Name == "Grass Training Pitch").DepartmentID
                },
                new Training {
                    TrainingID = 4022, Title = "Field practice", Credits = 3, DepartmentID = departments.Single(s => s.Name == "Artifical Grass Training Pitch").DepartmentID
                },
                new Training {
                    TrainingID = 4041, Title = "Gym", Credits = 3, DepartmentID = departments.Single(s => s.Name == "Gym").DepartmentID
                },
                new Training {
                    TrainingID = 1045, Title = "Stamina", Credits = 4, DepartmentID = departments.Single(s => s.Name == "Stadion").DepartmentID
                },
                new Training {
                    TrainingID = 3141, Title = "Sprints", Credits = 4, DepartmentID = departments.Single(s => s.Name == "Stadion").DepartmentID
                },
                new Training {
                    TrainingID = 2021, Title = "Tactics", Credits = 3, DepartmentID = departments.Single(s => s.Name == "Tactics Class").DepartmentID
                },
                new Training {
                    TrainingID = 2042, Title = "Gym", Credits = 4, DepartmentID = departments.Single(s => s.Name == "Gym").DepartmentID
                }
            };

            foreach (Training c in trainings)
            {
                context.Trainings.Add(c);
            }
            context.SaveChanges();


            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    StaffID  = staffs.Single(i => i.LastName == "Fakhouri").ID,
                    Location = "Smith 17"
                },
                new OfficeAssignment {
                    StaffID  = staffs.Single(i => i.LastName == "Harui").ID,
                    Location = "Gowan 27"
                },
                new OfficeAssignment {
                    StaffID  = staffs.Single(i => i.LastName == "Kapoor").ID,
                    Location = "Thompson 304"
                },
            };

            foreach (OfficeAssignment o in officeAssignments)
            {
                context.OfficeAssignments.Add(o);
            }
            context.SaveChanges();


            var trainingStaffs = new TrainingAssignment[]
            {
                new TrainingAssignment {
                    TrainingID = trainings.Single(c => c.Title == "Stamina" && c.DepartmentID == departments.Single(s => s.Name == "Stadion").DepartmentID).TrainingID,
                    StaffID    = staffs.Single(i => i.LastName == "Kapoor").ID
                },
                new TrainingAssignment {
                    TrainingID = trainings.Single(c => c.Title == "Gym" && c.DepartmentID == departments.Single(s => s.Name == "Gym").DepartmentID&& c.Credits == 3).TrainingID,
                    StaffID    = staffs.Single(i => i.LastName == "Harui").ID
                },
                new TrainingAssignment {
                    TrainingID = trainings.Single(c => c.Title == "Tactics" && c.DepartmentID == departments.Single(s => s.Name == "Tactics Class").DepartmentID).TrainingID,
                    StaffID    = staffs.Single(i => i.LastName == "Zheng").ID
                },
                new TrainingAssignment {
                    TrainingID = trainings.Single(c => c.Title == "Tactics" && c.DepartmentID == departments.Single(s => s.Name == "Tactics Class").DepartmentID).TrainingID,
                    StaffID    = staffs.Single(i => i.LastName == "Kapoor").ID
                },
                new TrainingAssignment {
                    TrainingID = trainings.Single(c => c.Title == "Field practice" && c.DepartmentID == departments.Single(s => s.Name == "Grass Training Pitch").DepartmentID).TrainingID,
                    StaffID    = staffs.Single(i => i.LastName == "Fakhouri").ID
                },
                new TrainingAssignment {
                    TrainingID = trainings.Single(c => c.Title == "Gym" && c.DepartmentID == departments.Single(s => s.Name == "Gym").DepartmentID&& c.Credits == 4).TrainingID,
                    StaffID    = staffs.Single(i => i.LastName == "Harui").ID
                },
                new TrainingAssignment {
                    TrainingID = trainings.Single(c => c.Title == "Field practice" && c.DepartmentID == departments.Single(s => s.Name == "Grass Training Pitch").DepartmentID).TrainingID,
                    StaffID    = staffs.Single(i => i.LastName == "Abercrombie").ID
                },
                new TrainingAssignment
                {
                    TrainingID = trainings.Single(c => c.Title == "Field practice" && c.DepartmentID == departments.Single(s => s.Name == "Artifical Grass Training Pitch").DepartmentID).TrainingID,
                    StaffID    = staffs.Single(i => i.LastName == "Abercrombie").ID
                }
            };

            foreach (TrainingAssignment ci in trainingStaffs)
            {
                context.TrainingAssignments.Add(ci);
            }
            context.SaveChanges();


            var signings = new Signing[]
            {
                new Signing {
                    PlayerID   = students.Single(s => s.LastName == "Alexander").ID,
                    TrainingID = trainings.Single(c => c.Title == "Field practice" && c.DepartmentID == departments.Single(s => s.Name == "Grass Training Pitch").DepartmentID).TrainingID,
                    Form       = Form.A
                },
                new Signing {
                    PlayerID   = students.Single(s => s.LastName == "Alexander").ID,
                    TrainingID = trainings.Single(c => c.Title == "Tactics" && c.DepartmentID == departments.Single(s => s.Name == "Tactics Class").DepartmentID).TrainingID,
                    Form       = Form.C
                },
                new Signing {
                    PlayerID   = students.Single(s => s.LastName == "Alexander").ID,
                    TrainingID = trainings.Single(c => c.Title == "Field practice" && c.DepartmentID == departments.Single(s => s.Name == "Artifical Grass Training Pitch").DepartmentID).TrainingID,
                    Form       = Form.B
                },
                new Signing {
                    PlayerID   = students.Single(s => s.LastName == "Alonso").ID,
                    TrainingID = trainings.Single(c => c.Title == "Field practice" && c.DepartmentID == departments.Single(s => s.Name == "Grass Training Pitch").DepartmentID).TrainingID,
                    Form       = Form.B
                },
                new Signing {
                    PlayerID   = students.Single(s => s.LastName == "Alonso").ID,
                    TrainingID = trainings.Single(c => c.Title == "Tactics" && c.DepartmentID == departments.Single(s => s.Name == "Tactics Class").DepartmentID).TrainingID,
                    Form       = Form.B
                },
                new Signing {
                    PlayerID   = students.Single(s => s.LastName == "Alonso").ID,
                    TrainingID = trainings.Single(c => c.Title == "Gym" && c.DepartmentID == departments.Single(s => s.Name == "Gym").DepartmentID&& c.Credits == 4).TrainingID,
                    Form       = Form.B
                },
                new Signing {
                    PlayerID   = students.Single(s => s.LastName == "Anand").ID,
                    TrainingID = trainings.Single(c => c.Title == "Gym" && c.DepartmentID == departments.Single(s => s.Name == "Gym").DepartmentID&& c.Credits == 3).TrainingID
                },
                new Signing {
                    PlayerID   = students.Single(s => s.LastName == "Anand").ID,
                    TrainingID = trainings.Single(c => c.Title == "Field practice" && c.DepartmentID == departments.Single(s => s.Name == "Artifical Grass Training Pitch").DepartmentID).TrainingID,
                    Form       = Form.B
                },
                new Signing {
                    PlayerID   = students.Single(s => s.LastName == "Barzdukas").ID,
                    TrainingID = trainings.Single(c => c.Title == "Tactics" && c.DepartmentID == departments.Single(s => s.Name == "Tactics Class").DepartmentID).TrainingID,
                    Form       = Form.B
                },
                new Signing {
                    PlayerID   = students.Single(s => s.LastName == "Li").ID,
                    TrainingID = trainings.Single(c => c.Title == "Gym" && c.DepartmentID == departments.Single(s => s.Name == "Gym").DepartmentID&& c.Credits == 4).TrainingID,
                    Form       = Form.B
                },
                new Signing {
                    PlayerID   = students.Single(s => s.LastName == "Justice").ID,
                    TrainingID = trainings.Single(c => c.Title == "Gym" && c.DepartmentID == departments.Single(s => s.Name == "Gym").DepartmentID&& c.Credits == 3).TrainingID,
                    Form       = Form.B
                }
            };

            foreach (Signing e in signings)
            {
                var signingInDataBase = context.Signings.Where(
                    s =>
                    s.Player.ID == e.PlayerID &&
                    s.Training.TrainingID == e.TrainingID).SingleOrDefault();
                if (signingInDataBase == null)
                {
                    context.Signings.Add(e);
                }
            }
            context.SaveChanges();
        }
Beispiel #15
0
        public static void Initialize(SchoolContext context)
        {
            context.Database.EnsureCreated();

            // Look For any students.
            if (context.Students.Any())
            {
                return; // DB has been seeded
            }

            // adding data to students
            var students = new Student[]
            {
                new Student {
                    FirstMidName = "Viqi", LastName = "Firdaus", EnrollmentDate = DateTime.Parse("2005-09-01")
                },
                new Student {
                    FirstMidName = "Fuad", LastName = "Abdullah", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    FirstMidName = "Irfan", LastName = "Khoirul", EnrollmentDate = DateTime.Parse("2003-09-01")
                },
                new Student {
                    FirstMidName = "Samsul", LastName = "Maarif", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    FirstMidName = "Rafi", LastName = "li", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    FirstMidName = "Agung", LastName = "Imamu", EnrollmentDate = DateTime.Parse("2001-09-01")
                },
                new Student {
                    FirstMidName = "Dila", LastName = "Nur", EnrollmentDate = DateTime.Parse("2003-09-01")
                },
                new Student {
                    FirstMidName = "Rima", LastName = "Wanti", EnrollmentDate = DateTime.Parse("2005-09-01")
                }
            };

            foreach (Student s in students)
            {
                context.Students.Add(s);
            }
            context.SaveChanges();



            // adding data to instructors
            var instructors = new Instructor[]
            {
                new Instructor {
                    FirstMidName = "Nana", LastName = "Ramadijanti",
                    HireDate     = DateTime.Parse("1995-03-11")
                },
                new Instructor {
                    FirstMidName = "Udin", LastName = "Harun",
                    HireDate     = DateTime.Parse("2002-07-06")
                },
                new Instructor {
                    FirstMidName = "Achmad", LastName = "Harui",
                    HireDate     = DateTime.Parse("1998-07-01")
                },
                new Instructor {
                    FirstMidName = "Muarifin", LastName = "Aja",
                    HireDate     = DateTime.Parse("2001-01-15")
                },
                new Instructor {
                    FirstMidName = "Achmad", LastName = "Basuki",
                    HireDate     = DateTime.Parse("2004-02-12")
                }
            };

            foreach (Instructor i in instructors)
            {
                context.Instructors.Add(i);
            }
            context.SaveChanges();

            // adding data to departemnts
            var departments = new Department[]
            {
                new Department {
                    Name         = "English", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Ramadijanti").ID
                },
                new Department {
                    Name         = "Mathematics", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Harun").ID
                },
                new Department {
                    Name         = "Engineering", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new Department {
                    Name         = "Economics", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Aja").ID
                }
            };

            foreach (Department d in departments)
            {
                context.Departments.Add(d);
            }
            context.SaveChanges();


            // adding data to  coursers
            var courses = new Course[]
            {
                new Course {
                    CourseID     = 1050, Title = "Chemistry", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Engineering").DepartmentID
                },
                new Course {
                    CourseID     = 4022, Title = "Microeconomics", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 4041, Title = "Macroeconomics", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 1045, Title = "Calculus", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 3141, Title = "Trigonometry", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 2021, Title = "Composition", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
                new Course {
                    CourseID     = 2042, Title = "literature", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
            };

            foreach (Course c in courses)
            {
                context.Courses.Add(c);
            }
            context.SaveChanges();

            // adding data to Enrollment
            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Firdaus").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.A
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Firdaus").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.C
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Firdaus").ID,
                    CourseID  = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Abdullah").ID,
                    CourseID  = courses.Single(c => c.Title == "Calculus").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Abdullah").ID,
                    CourseID  = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Abdullah").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Khoirul").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Khoirul").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Maarif").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "li").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Imamu").ID,
                    CourseID  = courses.Single(c => c.Title == "literature").CourseID,
                    Grade     = Grade.B
                }
            };

            foreach (Enrollment e in enrollments)
            {
                var enrollmentInDataBase = context.Enrollments.Where(
                    s =>
                    s.Student.ID == e.StudentID &&
                    s.Course.CourseID == e.CourseID).SingleOrDefault();
                if (enrollmentInDataBase == null)
                {
                    context.Enrollments.Add(e);
                }
            }
            context.SaveChanges();


            //adding data to OfficeAssignment
            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Harun").ID,
                    Location     = "Smith 17"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID,
                    Location     = "Gowan 27"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Aja").ID,
                    Location     = "Thompson 304"
                },
            };

            foreach (OfficeAssignment o in officeAssignments)
            {
                context.OfficeAssignments.Add(o);
            }
            context.SaveChanges();

            // adding data to CourseAssignment
            var courseInstructors = new CourseAssignment[]
            {
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Aja").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Basuki").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Basuki").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Calculus").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harun").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Composition").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Ramadijanti").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "literature").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Ramadijanti").ID
                },
            };

            foreach (CourseAssignment ci in courseInstructors)
            {
                context.CourseAssignments.Add(ci);
            }
            context.SaveChanges();
        }
 public async Task PutOfficeAssignmentAsync(int id, OfficeAssignment assignment)
 {
     assignment.InstructorId = id;
     db.OfficeAssignment.Update(assignment);
     await db.SaveChangesAsync();
 }
Beispiel #17
0
 public void Handle(Delete.Command message) => OfficeAssignment = null;
 public void InsertOfficeAssignment(OfficeAssignment officeAssignment)
 {
     officeAssignments.Add(officeAssignment);
 }
Beispiel #19
0
        public static void Initialize(SchoolContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.Students.Any())
            {
                return;   // DB has been seeded
            }

            var students = new Student[]
            {
                new Student {
                    FirstMidName = "Haldja", LastName = "Tooming", EnrollmentDate = DateTime.Parse("2007-09-01")
                },
                new Student {
                    FirstMidName = "Leedu", LastName = "Antero", EnrollmentDate = DateTime.Parse("2006-09-01")
                },
                new Student {
                    FirstMidName = "Artur", LastName = "Anni", EnrollmentDate = DateTime.Parse("2006-09-01")
                },
                new Student {
                    FirstMidName = "Frode", LastName = "Ester", EnrollmentDate = DateTime.Parse("2007-09-01")
                },
                new Student {
                    FirstMidName = "Jan", LastName = "Parve", EnrollmentDate = DateTime.Parse("2005-09-01")
                },
                new Student {
                    FirstMidName = "Jaak", LastName = "Valge", EnrollmentDate = DateTime.Parse("2006-09-01")
                },
                new Student {
                    FirstMidName = "Laura", LastName = "Oja", EnrollmentDate = DateTime.Parse("2005-09-01")
                },
                new Student {
                    FirstMidName = "Brenda", LastName = "Jaup", EnrollmentDate = DateTime.Parse("2006-09-01")
                }
            };

            foreach (Student s in students)
            {
                context.Students.Add(s);
            }
            context.SaveChanges();

            var instructors = new Instructor[]
            {
                new Instructor {
                    FirstMidName = "Sirje", LastName = "Tekko",
                    HireDate     = DateTime.Parse("1999-03-11")
                },
                new Instructor {
                    FirstMidName = "Merike", LastName = "Saar",
                    HireDate     = DateTime.Parse("2004-07-06")
                },
                new Instructor {
                    FirstMidName = "Kerli", LastName = "Jarve",
                    HireDate     = DateTime.Parse("1990-07-01")
                },
                new Instructor {
                    FirstMidName = "Anne", LastName = "Kuusmaa",
                    HireDate     = DateTime.Parse("2003-01-15")
                },
                new Instructor {
                    FirstMidName = "Bruno", LastName = "Nopponen",
                    HireDate     = DateTime.Parse("2004-03-12")
                }
            };

            foreach (Instructor i in instructors)
            {
                context.Instructors.Add(i);
            }
            context.SaveChanges();

            var departments = new Department[]
            {
                new Department {
                    Name         = "Languages", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Saar").ID
                },
                new Department {
                    Name         = "Mathematics", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Kuusmaa").ID
                },
                new Department {
                    Name         = "Sciences", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Tekko").ID
                },
                new Department {
                    Name         = "Sports", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Nopponen").ID
                }
            };

            foreach (Department d in departments)
            {
                context.Departments.Add(d);
            }
            context.SaveChanges();

            var courses = new Course[]
            {
                new Course {
                    CourseID = 1050, Title = "Chemistry", Credits = 3, DepartmentID = departments.Single(s => s.Name == "Sciences").DepartmentID
                },
                new Course {
                    CourseID = 4022, Title = "Biology", Credits = 3, DepartmentID = departments.Single(s => s.Name == "Sciences").DepartmentID
                },
                new Course {
                    CourseID = 4041, Title = "Swimming", Credits = 3, DepartmentID = departments.Single(s => s.Name == "Sports").DepartmentID
                },
                new Course {
                    CourseID = 1045, Title = "Athletics", Credits = 4, DepartmentID = departments.Single(s => s.Name == "Sports").DepartmentID
                },
                new Course {
                    CourseID = 3141, Title = "Math", Credits = 4, DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID = 2021, Title = "English", Credits = 3, DepartmentID = departments.Single(s => s.Name == "Languages").DepartmentID
                },
                new Course {
                    CourseID = 2042, Title = "Estonian", Credits = 4, DepartmentID = departments.Single(s => s.Name == "Languages").DepartmentID
                }
            };

            foreach (Course c in courses)
            {
                context.Courses.Add(c);
            }
            context.SaveChanges();


            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Tekko").ID,
                    Location     = "Sarapuu 17"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Jarve").ID,
                    Location     = "Pihlaka 27"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Kuusmaa").ID,
                    Location     = "Toomepuu 304"
                },
            };

            foreach (OfficeAssignment o in officeAssignments)
            {
                context.OfficeAssignments.Add(o);
            }
            context.SaveChanges();


            var courseInstructors = new CourseAssignment[]
            {
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Tekko").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Biology").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Tekko").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Swimming").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Nopponen").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Estonian").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Saar").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "English").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Saar").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Math").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Kuusmaa").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Athletics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Nopponen").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Athletics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Jarve").ID
                },
            };

            foreach (CourseAssignment ci in courseInstructors)
            {
                context.CourseAssignments.Add(ci);
            }
            context.SaveChanges();

            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Tooming").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Tooming").ID,
                    CourseID  = courses.Single(c => c.Title == "Swimming").CourseID,
                    Grade     = Grade.A
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Tooming").ID,
                    CourseID  = courses.Single(c => c.Title == "English").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Parve").ID,
                    CourseID  = courses.Single(c => c.Title == "Estonian").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Parve").ID,
                    CourseID  = courses.Single(c => c.Title == "Athletics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Parve").ID,
                    CourseID  = courses.Single(c => c.Title == "Biology").CourseID,
                    Grade     = Grade.C
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Oja").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Oja").ID,
                    CourseID  = courses.Single(c => c.Title == "Swimming").CourseID,
                    Grade     = Grade.A
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Jaup").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Valge").ID,
                    CourseID  = courses.Single(c => c.Title == "English").CourseID,
                    Grade     = Grade.C
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Valge").ID,
                    CourseID  = courses.Single(c => c.Title == "Estonian").CourseID,
                    Grade     = Grade.A
                }
            };

            foreach (Enrollment e in enrollments)
            {
                var enrollmentInDataBase = context.Enrollments.Where(
                    s =>
                    s.Student.ID == e.StudentID &&
                    s.Course.CourseID == e.CourseID).SingleOrDefault();
                if (enrollmentInDataBase == null)
                {
                    context.Enrollments.Add(e);
                }
            }
            context.SaveChanges();
        }
 public void DeleteOfficeAssignment(OfficeAssignment officeAssignment)
 {
     officeAssignments.Remove(officeAssignment);
 }
 public void InsertOfficeAssignment(OfficeAssignment officeAssignment)
 {
     context.OfficeAssignments.AddObject(officeAssignment);
     context.SaveChanges();
 }
 public void UpdateOfficeAssignment(OfficeAssignment officeAssignment, OfficeAssignment origOfficeAssignment)
 {
     officeAssignments.Remove(origOfficeAssignment);
     officeAssignments.Add(officeAssignment);
 }
 public void UpdateOfficeAssignment(OfficeAssignment officeAssignment, OfficeAssignment origOfficeAssignment)
 {
     context.OfficeAssignments.Attach(origOfficeAssignment);
     context.ApplyCurrentValues("OfficeAssignments", officeAssignment);
     SaveChanges();
 }
Beispiel #24
0
        public static void Initialize(SchoolContext context)
        {
            // context.Database.EnsureCreated();

            //this looks for any students
            if (context.Students.Any())
            {
                return;
            }
            var students = new Student[]
            {
                new Student {
                    FirstName = "Shuhratjan", LastName = "Nizamov", EnrollmentDate = DateTime.Parse("2005-09-01")
                },
                new Student {
                    FirstName = "Nurtileu", LastName = "Aliyas", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    FirstName = "Moldir", LastName = "Kaliyas", EnrollmentDate = DateTime.Parse("2003-09-01")
                },
                new Student {
                    FirstName = "Nazym", LastName = "Soltumuratova", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    FirstName = "Asanali", LastName = "Kereshov", EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    FirstName = "Muhamed", LastName = "Tolemis", EnrollmentDate = DateTime.Parse("2001-09-01")
                },
                new Student {
                    FirstName = "Saken", LastName = "Baymukhamed", EnrollmentDate = DateTime.Parse("2003-09-01")
                },
                new Student {
                    FirstName = "Asylzhan", LastName = "Erzhanov", EnrollmentDate = DateTime.Parse("2005-09-01")
                }
            };

            foreach (Student student in students)
            {
                context.Students.Add(student);
            }
            context.SaveChanges();

            var instructors = new Instructor[]
            {
                new Instructor {
                    FirstMidName = "Almas", LastName = "Byrleskenovich",
                    HireDate     = DateTime.Parse("2018-03-11")
                },
                new Instructor {
                    FirstMidName = "Gulbanu", LastName = "Khasenova",
                    HireDate     = DateTime.Parse("2002-07-06")
                },
                new Instructor {
                    FirstMidName = "Aizhan", LastName = "Doskozhanova",
                    HireDate     = DateTime.Parse("1998-07-01")
                },
                new Instructor {
                    FirstMidName = "Ilyas", LastName = "Zhuanishev",
                    HireDate     = DateTime.Parse("2001-01-15")
                },
                new Instructor {
                    FirstMidName = "Azamat", LastName = "Tolegenov",
                    HireDate     = DateTime.Parse("2004-02-12")
                }
            };

            foreach (Instructor i in instructors)
            {
                context.Instructors.Add(i);
            }
            context.SaveChanges();

            var departments = new Department[]
            {
                new Department {
                    Name         = "English", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Doskozhanova").ID
                },
                new Department {
                    Name         = "Mathematics", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Khasenova").ID
                },
                new Department {
                    Name         = "Engineering", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Byrleskenovich").ID
                },
                new Department {
                    Name         = "Economics", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Tolegenov").ID
                }
            };

            foreach (Department d in departments)
            {
                context.Departments.Add(d);
            }
            context.SaveChanges();

            var courses = new Course[]
            {
                new Course {
                    CourseID     = 1050, Title = "Chemistry", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Engineering").DepartmentID
                },
                new Course {
                    CourseID     = 4022, Title = "Microeconomics", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 4041, Title = "Macroeconomics", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 1045, Title = "Calculus", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 3141, Title = "Trigonometry", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 2021, Title = "Composition", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
                new Course {
                    CourseID     = 2042, Title = "Literature", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
            };

            foreach (Course c in courses)
            {
                context.Courses.Add(c);
            }
            context.SaveChanges();

            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Byrleskenovich").ID,
                    Location     = "Almaty 17"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Khasenova").ID,
                    Location     = "Astana 27"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Tolegenov").ID,
                    Location     = "Shymkent 304"
                },
            };

            foreach (OfficeAssignment o in officeAssignments)
            {
                context.OfficeAssignments.Add(o);
            }
            context.SaveChanges();

            var courseInstructors = new CourseAssignment[]
            {
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Tolegenov").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Khasenova").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Byrleskenovich").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Byrleskenovich").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Calculus").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Zhuanishev").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Khasenova").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Composition").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Doskozhanova").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Literature").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Doskozhanova").ID
                },
            };

            foreach (CourseAssignment ci in courseInstructors)
            {
                context.CourseAssignments.Add(ci);
            }
            context.SaveChanges();

            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Nizamov").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.A
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Aliyas").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.C
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Kaliyas").ID,
                    CourseID  = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Soltumuratova").ID,
                    CourseID  = courses.Single(c => c.Title == "Calculus").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Tolemis").ID,
                    CourseID  = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Nizamov").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Aliyas").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Kaliyas").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Soltumuratova").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Erzhanov").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Baymukhamed").ID,
                    CourseID  = courses.Single(c => c.Title == "Literature").CourseID,
                    Grade     = Grade.B
                }
            };

            foreach (Enrollment e in enrollments)
            {
                var enrollmentInDataBase = context.Enrollments.Where(
                    s =>
                    s.Student.ID == e.StudentID &&
                    s.Course.CourseID == e.CourseID).SingleOrDefault();
                if (enrollmentInDataBase == null)
                {
                    context.Enrollments.Add(e);
                }
            }
            context.SaveChanges();
        }
Beispiel #25
0
        public static void Initialize(CollegeContext context)
        {
            //context.Database.EnsureCreated();

            // Look for any students.
            if (context.Students.Any())
            {
                return;   // DB has been seeded
            }

            var students = new Student[]
            {
                new Student {
                    FirstMidName   = "Carson", LastName = "Alexander",
                    EnrollmentDate = DateTime.Parse("2010-09-01"), DOB = DateTime.Parse("1995-09-18")
                },
                new Student {
                    FirstMidName   = "Meredith", LastName = "Alonso",
                    EnrollmentDate = DateTime.Parse("2012-09-01"), DOB = DateTime.Parse("1997-10-08")
                },
                new Student {
                    FirstMidName   = "Arturo", LastName = "Anand",
                    EnrollmentDate = DateTime.Parse("2013-09-01"), DOB = DateTime.Parse("1996-02-10")
                },
                new Student {
                    FirstMidName   = "Gytis", LastName = "Barzdukas",
                    EnrollmentDate = DateTime.Parse("2012-09-01"), DOB = DateTime.Parse("1995-07-01")
                },
                new Student {
                    FirstMidName   = "Yan", LastName = "Li",
                    EnrollmentDate = DateTime.Parse("2012-09-01"), DOB = DateTime.Parse("1995-03-30")
                },
                new Student {
                    FirstMidName   = "Peggy", LastName = "Justice",
                    EnrollmentDate = DateTime.Parse("2011-09-01"), DOB = DateTime.Parse("1994-06-26")
                },
                new Student {
                    FirstMidName   = "Laura", LastName = "Norman",
                    EnrollmentDate = DateTime.Parse("2013-09-01"), DOB = DateTime.Parse("1995-03-14")
                },
                new Student {
                    FirstMidName   = "Nino", LastName = "Olivetto",
                    EnrollmentDate = DateTime.Parse("2005-09-01"), DOB = DateTime.Parse("1997-05-10")
                }
            };

            foreach (Student s in students)
            {
                context.Students.Add(s);
            }
            context.SaveChanges();

            var instructors = new Lecturer[]
            {
                new Lecturer {
                    FirstMidName = "Kim", LastName = "Ridge",
                    HireDate     = DateTime.Parse("1995-03-11"), EmailAddress = "*****@*****.**"
                },
                new Lecturer {
                    FirstMidName = "Fadi", LastName = "Fally",
                    HireDate     = DateTime.Parse("2002-07-06"), EmailAddress = "*****@*****.**"
                },
                new Lecturer {
                    FirstMidName = "Roger", LastName = "Harui",
                    HireDate     = DateTime.Parse("1998-07-01"), EmailAddress = "*****@*****.**"
                },
                new Lecturer {
                    FirstMidName = "Candace", LastName = "Kapoor",
                    HireDate     = DateTime.Parse("2001-01-15"), EmailAddress = "*****@*****.**"
                },
                new Lecturer {
                    FirstMidName = "Roger", LastName = "Zheng",
                    HireDate     = DateTime.Parse("2004-02-12"), EmailAddress = "*****@*****.**"
                }
            };

            /*
             * if (context.Lecturers.Any())
             * {
             *  return;   // DB has been seeded
             * }
             */

            foreach (Lecturer i in instructors)
            {
                context.Lecturers.Add(i);
            }
            context.SaveChanges();


            if (context.Departments.Any())
            {
                return;   // DB has been seeded
            }


            var departments = new Department[]
            {
                new Department {
                    Name       = "English", Budget = 350000,
                    StartDate  = DateTime.Parse("2007-09-01"),
                    LecturerID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new Department {
                    Name       = "Mathematics", Budget = 100000,
                    StartDate  = DateTime.Parse("2007-09-01"),
                    LecturerID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new Department {
                    Name       = "Engineering", Budget = 350000,
                    StartDate  = DateTime.Parse("2007-09-01"),
                    LecturerID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new Department {
                    Name       = "Economics", Budget = 100000,
                    StartDate  = DateTime.Parse("2007-09-01"),
                    LecturerID = instructors.Single(i => i.LastName == "Kapoor").ID
                }
            };

            foreach (Department d in departments)
            {
                context.Departments.Add(d);
            }
            context.SaveChanges();

            //  if (context.Courses.Any())
            //{
            //  return;   // DB has been seeded
            //}


            var courses = new Course[]
            {
                new Course {
                    CourseID     = 1050, Title = "Chemistry", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Engineering").DepartmentID
                },
                new Course {
                    CourseID     = 4022, Title = "Microeconomics", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 4041, Title = "Macroeconomics", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 1045, Title = "Calculus", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 3141, Title = "Trigonometry", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 2021, Title = "Composition", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
                new Course {
                    CourseID     = 2042, Title = "Literature", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
            };

            foreach (Course c in courses)
            {
                context.Courses.Add(c);
            }
            context.SaveChanges();

            //if (context.OfficeAssignments.Any())
            //{
            //  return;   // DB has been seeded
            //}


            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    LecturerID = instructors.Single(i => i.LastName == "Fakhouri").ID,
                    Location   = "Smith 17"
                },
                new OfficeAssignment {
                    LecturerID = instructors.Single(i => i.LastName == "Harui").ID,
                    Location   = "Gowan 27"
                },
                new OfficeAssignment {
                    LecturerID = instructors.Single(i => i.LastName == "Kapoor").ID,
                    Location   = "Thompson 304"
                },
            };

            foreach (OfficeAssignment o in officeAssignments)
            {
                context.OfficeAssignments.Add(o);
            }
            context.SaveChanges();

            if (context.CourseAssignments.Any())
            {
                return;   // DB has been seeded
            }

            var courseInstructors = new CourseAssignment[]
            {
                new CourseAssignment {
                    CourseID   = courses.Single(c => c.Title == "Chemistry").CourseID,
                    LecturerID = instructors.Single(i => i.LastName == "Kapoor").ID
                },
                new CourseAssignment {
                    CourseID   = courses.Single(c => c.Title == "Chemistry").CourseID,
                    LecturerID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID   = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    LecturerID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID   = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    LecturerID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID   = courses.Single(c => c.Title == "Calculus").CourseID,
                    LecturerID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new CourseAssignment {
                    CourseID   = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    LecturerID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID   = courses.Single(c => c.Title == "Composition").CourseID,
                    LecturerID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new CourseAssignment {
                    CourseID   = courses.Single(c => c.Title == "Literature").CourseID,
                    LecturerID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
            };

            foreach (CourseAssignment ci in courseInstructors)
            {
                context.CourseAssignments.Add(ci);
            }
            context.SaveChanges();

            // if (context.Enrollments.Any())
            //{
            //  return;   // DB has been seeded
            //}


            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.A
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.C
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Calculus").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Anand").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Anand").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Barzdukas").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Li").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Justice").ID,
                    CourseID  = courses.Single(c => c.Title == "Literature").CourseID,
                    Grade     = Grade.B
                }
            };

            foreach (Enrollment e in enrollments)
            {
                var enrollmentInDataBase = context.Enrollments.Where(
                    s =>
                    s.Student.ID == e.StudentID &&
                    s.Course.CourseID == e.CourseID).SingleOrDefault();
                if (enrollmentInDataBase == null)
                {
                    context.Enrollments.Add(e);
                }
            }
            context.SaveChanges();
        }
 public ActionResult <OfficeAssignment> PostOfficeAssignment(OfficeAssignment model)
 {
     db.OfficeAssignment.Add(model);
     db.SaveChanges();
     return(Created("/api/OfficeAssignment/" + model.InstructorId, model));
 }
Beispiel #27
0
        public static void Initialize(SchoolContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.Students.Any())
            {
                return;   // DB has been seeded
            }

            var students = new Student[]
            {
                new Student {
                    FirstMidName   = "Joe", LastName = "Banana",
                    EnrollmentDate = DateTime.Parse("2010-01-01")
                },
                new Student {
                    FirstMidName   = "Sofia", LastName = "Berlin",
                    EnrollmentDate = DateTime.Parse("2012-01-01")
                },
                new Student {
                    FirstMidName   = "Silistra", LastName = "Busters",
                    EnrollmentDate = DateTime.Parse("2013-01-01")
                },
                new Student {
                    FirstMidName   = "Ivan", LastName = "B.",
                    EnrollmentDate = DateTime.Parse("2012-01-01")
                },
                new Student {
                    FirstMidName   = "Mina", LastName = "Batman",
                    EnrollmentDate = DateTime.Parse("2011-01-01")
                },
                new Student {
                    FirstMidName   = "Pesho", LastName = "Zorro",
                    EnrollmentDate = DateTime.Parse("2013-01-01")
                },
                new Student {
                    FirstMidName   = "Hristomir", LastName = "Hristov",
                    EnrollmentDate = DateTime.Parse("2005-01-01")
                }
            };

            foreach (Student s in students)
            {
                context.Students.Add(s);
            }
            context.SaveChanges();

            var instructors = new Instructor[]
            {
                new Instructor {
                    FirstMidName = "Krachun", LastName = "Malchov",
                    HireDate     = DateTime.Parse("1995-03-11")
                },
                new Instructor {
                    FirstMidName = "Safadi", LastName = "Yordanov",
                    HireDate     = DateTime.Parse("2002-07-06")
                },
                new Instructor {
                    FirstMidName = "Hristo", LastName = "Stoichkov",
                    HireDate     = DateTime.Parse("1998-07-01")
                },
                new Instructor {
                    FirstMidName = "Yordan", LastName = "Lechkov",
                    HireDate     = DateTime.Parse("2001-01-15")
                },
                new Instructor {
                    FirstMidName = "Hristo", LastName = "Zhabov",
                    HireDate     = DateTime.Parse("2004-02-12")
                }
            };

            foreach (Instructor i in instructors)
            {
                context.Instructors.Add(i);
            }
            context.SaveChanges();

            var departments = new Department[]
            {
                new Department {
                    Name         = "Advanced Design", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorId = instructors.Single(i => i.LastName == "Malchov").Id
                },
                new Department {
                    Name         = "Design", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorId = instructors.Single(i => i.LastName == "Yordanov").Id
                },
                new Department {
                    Name         = "Advanced Structures", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorId = instructors.Single(i => i.LastName == "Stoichkov").Id
                },
                new Department {
                    Name         = "Advanced Programming", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorId = instructors.Single(i => i.LastName == "Lechkov").Id
                }
            };

            foreach (Department d in departments)
            {
                context.Departments.Add(d);
            }
            context.SaveChanges();

            var courses = new Course[]
            {
                new Course {
                    CourseId     = 1050, Title = "General Programming", Credits = 3,
                    DepartmentId = departments.Single(s => s.Name == "Advanced Structures").DepartmentId
                },
                new Course {
                    CourseId     = 4022, Title = "Programming 101", Credits = 3,
                    DepartmentId = departments.Single(s => s.Name == "Advanced Programming").DepartmentId
                },
                new Course {
                    CourseId     = 4041, Title = "Programming 201", Credits = 3,
                    DepartmentId = departments.Single(s => s.Name == "Advanced Programming").DepartmentId
                },
                new Course {
                    CourseId     = 1045, Title = "Algorithms", Credits = 4,
                    DepartmentId = departments.Single(s => s.Name == "Design").DepartmentId
                },
                new Course {
                    CourseId     = 3141, Title = "Front End", Credits = 4,
                    DepartmentId = departments.Single(s => s.Name == "Design").DepartmentId
                },
                new Course {
                    CourseId     = 2021, Title = "Back End", Credits = 3,
                    DepartmentId = departments.Single(s => s.Name == "Advanced Design").DepartmentId
                },
                new Course {
                    CourseId     = 2042, Title = "CSS", Credits = 4,
                    DepartmentId = departments.Single(s => s.Name == "Advanced Design").DepartmentId
                },
            };

            foreach (Course c in courses)
            {
                context.Courses.Add(c);
            }
            context.SaveChanges();

            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    InstructorId = instructors.Single(i => i.LastName == "Yordanov").Id,
                    Location     = "Nuremberg"
                },
                new OfficeAssignment {
                    InstructorId = instructors.Single(i => i.LastName == "Stoichkov").Id,
                    Location     = "Sofia"
                },
                new OfficeAssignment {
                    InstructorId = instructors.Single(i => i.LastName == "Lechkov").Id,
                    Location     = "Silistra"
                },
            };

            foreach (OfficeAssignment o in officeAssignments)
            {
                context.OfficeAssignments.Add(o);
            }
            context.SaveChanges();

            var courseInstructors = new CourseAssignment[]
            {
                new CourseAssignment {
                    CourseId     = courses.Single(c => c.Title == "General Programming").CourseId,
                    InstructorId = instructors.Single(i => i.LastName == "Lechkov").Id
                },
                new CourseAssignment {
                    CourseId     = courses.Single(c => c.Title == "General Programming").CourseId,
                    InstructorId = instructors.Single(i => i.LastName == "Stoichkov").Id
                },
                new CourseAssignment {
                    CourseId     = courses.Single(c => c.Title == "Programming 101").CourseId,
                    InstructorId = instructors.Single(i => i.LastName == "Zhabov").Id
                },
                new CourseAssignment {
                    CourseId     = courses.Single(c => c.Title == "Programming 201").CourseId,
                    InstructorId = instructors.Single(i => i.LastName == "Zhabov").Id
                },
                new CourseAssignment {
                    CourseId     = courses.Single(c => c.Title == "Algorithms").CourseId,
                    InstructorId = instructors.Single(i => i.LastName == "Yordanov").Id
                },
                new CourseAssignment {
                    CourseId     = courses.Single(c => c.Title == "Front End").CourseId,
                    InstructorId = instructors.Single(i => i.LastName == "Stoichkov").Id
                },
                new CourseAssignment {
                    CourseId     = courses.Single(c => c.Title == "Back End").CourseId,
                    InstructorId = instructors.Single(i => i.LastName == "Malchov").Id
                },
                new CourseAssignment {
                    CourseId     = courses.Single(c => c.Title == "CSS").CourseId,
                    InstructorId = instructors.Single(i => i.LastName == "Malchov").Id
                },
            };

            foreach (CourseAssignment ci in courseInstructors)
            {
                context.CourseAssignments.Add(ci);
            }
            context.SaveChanges();

            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    StudentId = students.Single(s => s.LastName == "Banana").Id,
                    CourseId  = courses.Single(c => c.Title == "General Programming").CourseId,
                    Grade     = Grade.A
                },
                new Enrollment {
                    StudentId = students.Single(s => s.LastName == "Banana").Id,
                    CourseId  = courses.Single(c => c.Title == "Programming 101").CourseId,
                    Grade     = Grade.C
                },
                new Enrollment {
                    StudentId = students.Single(s => s.LastName == "Banana").Id,
                    CourseId  = courses.Single(c => c.Title == "Programming 201").CourseId,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentId = students.Single(s => s.LastName == "Berlin").Id,
                    CourseId  = courses.Single(c => c.Title == "Algorithms").CourseId,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentId = students.Single(s => s.LastName == "Berlin").Id,
                    CourseId  = courses.Single(c => c.Title == "Front End").CourseId,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentId = students.Single(s => s.LastName == "Berlin").Id,
                    CourseId  = courses.Single(c => c.Title == "Back End").CourseId,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentId = students.Single(s => s.LastName == "Busters").Id,
                    CourseId  = courses.Single(c => c.Title == "General Programming").CourseId
                },
                new Enrollment {
                    StudentId = students.Single(s => s.LastName == "Busters").Id,
                    CourseId  = courses.Single(c => c.Title == "Programming 101").CourseId,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentId = students.Single(s => s.LastName == "B.").Id,
                    CourseId  = courses.Single(c => c.Title == "General Programming").CourseId,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentId = students.Single(s => s.LastName == "Batman").Id,
                    CourseId  = courses.Single(c => c.Title == "CSS").CourseId,
                    Grade     = Grade.B
                }
            };

            foreach (Enrollment e in enrollments)
            {
                var enrollmentInDataBase = context.Enrollments.Where(
                    s =>
                    s.Student.Id == e.StudentId &&
                    s.Course.CourseId == e.CourseId).SingleOrDefault();
                if (enrollmentInDataBase == null)
                {
                    context.Enrollments.Add(e);
                }
            }
            context.SaveChanges();
        }
Beispiel #28
0
        public static void Initialize(SchoolContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.Students.Any())
            {
                return;   // DB has been seeded
            }

            // sample data for Student
            var students = new Student[]
            {
                new Student {
                    FirstName = "Carson", LastName = "Alexander", EmailAddress = "*****@*****.**", YearRank = "Junior", AverageGrade = 3.4f, EnrollmentDate = DateTime.Parse("2005-09-01")
                },
                new Student {
                    FirstName = "Meredith", LastName = "Alonso", EmailAddress = "*****@*****.**", YearRank = "Junior", AverageGrade = 2.9f, EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    FirstName = "Arturo", LastName = "Anand", EmailAddress = "*****@*****.**", YearRank = "Sophomore", AverageGrade = 3.9f, EnrollmentDate = DateTime.Parse("2003-09-01")
                },
                new Student {
                    FirstName = "Gytis", LastName = "Barzdukas", EmailAddress = "*****@*****.**", YearRank = "Freshmen", AverageGrade = 3.5f, EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    FirstName = "Yan", LastName = "Li", EmailAddress = "*****@*****.**", YearRank = "Senior", AverageGrade = 2.3f, EnrollmentDate = DateTime.Parse("2002-09-01")
                },
                new Student {
                    FirstName = "Peggy", LastName = "Justice", EmailAddress = "*****@*****.**", YearRank = "Junior", AverageGrade = 3.2f, EnrollmentDate = DateTime.Parse("2001-09-01")
                },
                new Student {
                    FirstName = "Laura", LastName = "Norman", EmailAddress = "*****@*****.**", YearRank = "Freshmen", AverageGrade = 3.1f, EnrollmentDate = DateTime.Parse("2003-09-01")
                },
                new Student {
                    FirstName = "Nino", LastName = "Olivetto", EmailAddress = "*****@*****.**", YearRank = "Senior", AverageGrade = 4.0f, EnrollmentDate = DateTime.Parse("2005-09-01")
                }
            };

            foreach (Student s in students)
            {
                context.Students.Add(s);
            }
            context.SaveChanges();


            // sample data for Instructor
            var instructors = new Instructor[]
            {
                new Instructor {
                    FirstName = "Kim", LastName = "Abercrombie",
                    HireDate  = DateTime.Parse("1995-03-11")
                },
                new Instructor {
                    FirstName = "Fadi", LastName = "Fakhouri",
                    HireDate  = DateTime.Parse("2002-07-06")
                },
                new Instructor {
                    FirstName = "Roger", LastName = "Harui",
                    HireDate  = DateTime.Parse("1998-07-01")
                },
                new Instructor {
                    FirstName = "Candace", LastName = "Kapoor",
                    HireDate  = DateTime.Parse("2001-01-15")
                },
                new Instructor {
                    FirstName = "Roger", LastName = "Zheng",
                    HireDate  = DateTime.Parse("2004-02-12")
                },
                new Instructor {
                    FirstName = "John", LastName = "David",
                    HireDate  = DateTime.Parse("2004-03-10")
                }
            };

            foreach (Instructor i in instructors)
            {
                context.Instructors.Add(i);
            }
            context.SaveChanges();


            // sample data for Department
            var departments = new Department[]
            {
                new Department {
                    Name         = "English", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new Department {
                    Name         = "Mathematics", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new Department {
                    Name         = "Engineering", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new Department {
                    Name         = "Economics", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID
                },
                new Department {
                    Name         = "Information Technology", Budget = 200000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "David").ID
                }
            };

            foreach (Department d in departments)
            {
                context.Departments.Add(d);
            }
            context.SaveChanges();

            // sample data for Course
            var courses = new Course[]
            {
                new Course {
                    CourseID     = 1050, Title = "Chemistry", Credits = 3, RoomNum = "BHS 409",
                    DepartmentID = departments.Single(s => s.Name == "Engineering").DepartmentID
                },
                new Course {
                    CourseID     = 4022, Title = "Microeconomics", Credits = 3, RoomNum = "CP 503",
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 4041, Title = "Macroeconomics", Credits = 3, RoomNum = "WG 689",
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 1045, Title = "Calculus", Credits = 4, RoomNum = "GWP 110",
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 3141, Title = "Trigonometry", Credits = 4, RoomNum = "MAT 941",
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 2021, Title = "Composition", Credits = 3, RoomNum = "WCG 001",
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
                new Course {
                    CourseID     = 2042, Title = "Literature", Credits = 4, RoomNum = "BB 276",
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
                new Course {
                    CourseID     = 2078, Title = "ASP.NET MVC Web App", Credits = 4, RoomNum = "BB 276",
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                }
            };

            foreach (Course c in courses)
            {
                context.Courses.Add(c);
            }
            context.SaveChanges();

            // sample data for Enrollment
            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.A
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.C
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Calculus").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Anand").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Anand").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Barzdukas").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Li").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Justice").ID,
                    CourseID  = courses.Single(c => c.Title == "Literature").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Olivetto").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.A
                }
            };

            foreach (Enrollment e in enrollments)
            {
                var enrollmentInDataBase = context.Enrollments.Where(
                    s =>
                    s.Student.ID == e.StudentID &&
                    s.Course.CourseID == e.CourseID).SingleOrDefault();
                if (enrollmentInDataBase == null)
                {
                    context.Enrollments.Add(e);
                }
            }
            context.SaveChanges();


            // sample data for Office Assignment
            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID,
                    Location     = "Smith 17"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID,
                    Location     = "Gowan 27"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID,
                    Location     = "Thompson 304"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "David").ID,
                    Location     = "MAT 304"
                },
            };

            foreach (OfficeAssignment o in officeAssignments)
            {
                context.OfficeAssignments.Add(o);
            }
            context.SaveChanges();


            // sample data for Course Assignment
            var courseInstructors = new CourseAssignment[]
            {
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Calculus").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Composition").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Literature").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
            };

            foreach (CourseAssignment ci in courseInstructors)
            {
                context.CourseAssignments.Add(ci);
            }
            context.SaveChanges();
        }
Beispiel #29
0
        public static void Initialize(SchoolContext context)
        {
            //context.Database.EnsureCreated();

            // Look for any students.
            if (context.Students.Any())
            {
                return;   // DB has been seeded
            }

            var students = new Student[]
            {
                new Student {
                    FirstMidName   = "Carson", LastName = "Alexander",
                    EnrollmentDate = DateTime.Parse("2010-09-01")
                },
                new Student {
                    FirstMidName   = "Meredith", LastName = "Alonso",
                    EnrollmentDate = DateTime.Parse("2012-09-01")
                },
                new Student {
                    FirstMidName   = "Arturo", LastName = "Anand",
                    EnrollmentDate = DateTime.Parse("2013-09-01")
                },
                new Student {
                    FirstMidName   = "Gytis", LastName = "Barzdukas",
                    EnrollmentDate = DateTime.Parse("2012-09-01")
                },
                new Student {
                    FirstMidName   = "Yan", LastName = "Li",
                    EnrollmentDate = DateTime.Parse("2012-09-01")
                },
                new Student {
                    FirstMidName   = "Peggy", LastName = "Justice",
                    EnrollmentDate = DateTime.Parse("2011-09-01")
                },
                new Student {
                    FirstMidName   = "Laura", LastName = "Norman",
                    EnrollmentDate = DateTime.Parse("2013-09-01")
                },
                new Student {
                    FirstMidName   = "Nino", LastName = "Olivetto",
                    EnrollmentDate = DateTime.Parse("2005-09-01")
                }
            };

            context.Students.AddRange(students);
            context.SaveChanges();

            var instructors = new Instructor[]
            {
                new Instructor {
                    FirstMidName = "Kim", LastName = "Abercrombie",
                    HireDate     = DateTime.Parse("1995-03-11")
                },
                new Instructor {
                    FirstMidName = "Fadi", LastName = "Fakhouri",
                    HireDate     = DateTime.Parse("2002-07-06")
                },
                new Instructor {
                    FirstMidName = "Roger", LastName = "Harui",
                    HireDate     = DateTime.Parse("1998-07-01")
                },
                new Instructor {
                    FirstMidName = "Candace", LastName = "Kapoor",
                    HireDate     = DateTime.Parse("2001-01-15")
                },
                new Instructor {
                    FirstMidName = "Roger", LastName = "Zheng",
                    HireDate     = DateTime.Parse("2004-02-12")
                }
            };

            context.Instructors.AddRange(instructors);
            context.SaveChanges();

            var departments = new Department[]
            {
                new Department {
                    Name         = "English", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new Department {
                    Name         = "Mathematics", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new Department {
                    Name         = "Engineering", Budget = 350000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new Department {
                    Name         = "Economics", Budget = 100000,
                    StartDate    = DateTime.Parse("2007-09-01"),
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID
                }
            };

            context.Departments.AddRange(departments);
            context.SaveChanges();

            var courses = new Course[]
            {
                new Course {
                    CourseID     = 1050, Title = "Chemistry", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Engineering").DepartmentID
                },
                new Course {
                    CourseID     = 4022, Title = "Microeconomics", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 4041, Title = "Macroeconomics", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "Economics").DepartmentID
                },
                new Course {
                    CourseID     = 1045, Title = "Calculus", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 3141, Title = "Trigonometry", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "Mathematics").DepartmentID
                },
                new Course {
                    CourseID     = 2021, Title = "Composition", Credits = 3,
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
                new Course {
                    CourseID     = 2042, Title = "Literature", Credits = 4,
                    DepartmentID = departments.Single(s => s.Name == "English").DepartmentID
                },
            };

            foreach (Course c in courses)
            {
                context.Courses.Add(c);
            }
            context.SaveChanges();

            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID,
                    Location     = "Smith 17"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID,
                    Location     = "Gowan 27"
                },
                new OfficeAssignment {
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID,
                    Location     = "Thompson 304"
                },
            };

            context.OfficeAssignments.AddRange(officeAssignments);
            context.SaveChanges();

            var courseInstructors = new CourseAssignment[]
            {
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Chemistry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Zheng").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Calculus").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Harui").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Composition").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
                new CourseAssignment {
                    CourseID     = courses.Single(c => c.Title == "Literature").CourseID,
                    InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID
                },
            };

            context.CourseAssignments.AddRange(courseInstructors);
            context.SaveChanges();

            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.A
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.C
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alexander").ID,
                    CourseID  = courses.Single(c => c.Title == "Macroeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Calculus").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Trigonometry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Alonso").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Anand").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Anand").ID,
                    CourseID  = courses.Single(c => c.Title == "Microeconomics").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Barzdukas").ID,
                    CourseID  = courses.Single(c => c.Title == "Chemistry").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Li").ID,
                    CourseID  = courses.Single(c => c.Title == "Composition").CourseID,
                    Grade     = Grade.B
                },
                new Enrollment {
                    StudentID = students.Single(s => s.LastName == "Justice").ID,
                    CourseID  = courses.Single(c => c.Title == "Literature").CourseID,
                    Grade     = Grade.B
                }
            };

            foreach (Enrollment e in enrollments)
            {
                var enrollmentInDataBase = context.Enrollments.Where(
                    s =>
                    s.Student.ID == e.StudentID &&
                    s.Course.CourseID == e.CourseID).SingleOrDefault();
                if (enrollmentInDataBase == null)
                {
                    context.Enrollments.Add(e);
                }
            }
            context.SaveChanges();
        }
Beispiel #30
0
        public static void Initialize(SchoolContext context)
        {
            // Look for any students
            if (context.Students.Any())
            {
                Console.WriteLine("Found one");
                // DB has data or has been seeded
                return;
            }
            Console.WriteLine("None found");

            // students
            var studentPM = new Student {
                FirstMidName = "Peter", LastName = "Mayaga", EnrollmentDate = DateTime.Parse("2015-05-03")
            };
            var studentJK = new Student {
                FirstMidName = "John", LastName = "Kampulunguse", EnrollmentDate = DateTime.Parse("2018-12-30")
            };
            var studentWS = new Student {
                FirstMidName = "Were", LastName = "Simon", EnrollmentDate = DateTime.Parse("2020-10-21")
            };
            var studentCJ = new Student {
                FirstMidName = "Collins", LastName = "Jackson", EnrollmentDate = DateTime.Parse("2009-01-02")
            };
            var studentMS = new Student {
                FirstMidName = "Matthew", LastName = "Sekitoleko", EnrollmentDate = DateTime.Parse("2021-3-23")
            };

            // instructors
            var instructor1 = new Instructor {
                FirstMidName = "John", LastName = "Ung", HireDate = DateTime.Parse("2001-04-14")
            };
            var instructor2 = new Instructor {
                FirstMidName = "Kabenge", LastName = "Moses", HireDate = DateTime.Parse("2005-01-29")
            };
            var instructor3 = new Instructor {
                FirstMidName = "Ssenoga", LastName = "Abram", HireDate = DateTime.Parse("2001-11-02")
            };
            var instructor4 = new Instructor {
                FirstMidName = "Wandegeya", LastName = "Kulekana", HireDate = DateTime.Parse("2015-10-30")
            };

            // OfficeAssignments
            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    Instructor = instructor1, Location = "LLT-1A"
                },
                new OfficeAssignment {
                    Instructor = instructor3, Location = "LLT-2B"
                },
                new OfficeAssignment {
                    Instructor = instructor4, Location = "Big lab A"
                }
            };

            context.AddRange(officeAssignments);

            // departments
            var english = new Department
            {
                Name          = "English",
                Budget        = 300000,
                StartDate     = DateTime.Parse("1990-02-15"),
                Administrator = instructor1
            };
            var mathematics = new Department
            {
                Name          = "Mathematics",
                Budget        = 250000,
                StartDate     = DateTime.Parse("1960-10-25"),
                Administrator = instructor2
            };
            var cs = new Department
            {
                Name          = "Computer Science",
                Budget        = 500000,
                StartDate     = DateTime.Parse("1990-09-22"),
                Administrator = instructor3
            };

            // courses
            var chemistry = new Course
            {
                CourseID    = 1050,
                Title       = "Chemistry",
                Credits     = 3,
                Department  = mathematics,
                Instructors = new List <Instructor> {
                    instructor1, instructor2
                }
            };
            var SE = new Course
            {
                CourseID    = 5060,
                Title       = "Software Engineering",
                Credits     = 4,
                Department  = cs,
                Instructors = new List <Instructor> {
                    instructor2, instructor3
                }
            };
            var discreteMaths = new Course
            {
                CourseID    = 5090,
                Title       = "Discrete Mathematics",
                Credits     = 5,
                Department  = cs,
                Instructors = new List <Instructor> {
                    instructor2, instructor3, instructor4
                }
            };

            // Enrollments
            var enrollments = new Enrollment[]
            {
                new Enrollment
                {
                    Student = studentCJ,
                    Course  = chemistry,
                    Grade   = Grade.D
                },
                new Enrollment
                {
                    Student = studentJK,
                    Course  = discreteMaths
                },
                new Enrollment
                {
                    Student = studentPM,
                    Course  = SE,
                    Grade   = Grade.A
                },
                new Enrollment
                {
                    Student = studentJK,
                    Course  = SE,
                    Grade   = Grade.B
                },
                new Enrollment
                {
                    Student = studentMS,
                    Course  = chemistry
                }
                // studentWS not used
            };

            context.AddRange(enrollments);

            // Save changes
            context.SaveChanges();
        }
 /// <summary>
 /// Create a new OfficeAssignment object.
 /// </summary>
 /// <param name="instructorID">Initial value of InstructorID.</param>
 /// <param name="location">Initial value of Location.</param>
 /// <param name="timestamp">Initial value of Timestamp.</param>
 public static OfficeAssignment CreateOfficeAssignment(int instructorID, string location, byte[] timestamp)
 {
     OfficeAssignment officeAssignment = new OfficeAssignment();
     officeAssignment.InstructorID = instructorID;
     officeAssignment.Location = location;
     officeAssignment.Timestamp = timestamp;
     return officeAssignment;
 }
Beispiel #32
0
        public static void Initialize(SchoolContext context)
        {
            context.Database.EnsureCreated();

            if (context.students.Any())
            {
                return;
            }

            var students = new Student[]
            {
                new Student {
                    firstName = "Carson", lastName = "Alexander", dateEnrollment = DateTime.Parse("2005-09-01")
                },
                new Student {
                    firstName = "Meredith", lastName = "Alonso", dateEnrollment = DateTime.Parse("2002-09-01")
                },
                new Student {
                    firstName = "Arturo", lastName = "Anand", dateEnrollment = DateTime.Parse("2003-09-01")
                },
                new Student {
                    firstName = "Gytis", lastName = "Barzdukas", dateEnrollment = DateTime.Parse("2002-09-01")
                },
                new Student {
                    firstName = "Yan", lastName = "Li", dateEnrollment = DateTime.Parse("2002-09-01")
                },
                new Student {
                    firstName = "Peggy", lastName = "Justice", dateEnrollment = DateTime.Parse("2001-09-01")
                },
                new Student {
                    firstName = "Laura", lastName = "Norman", dateEnrollment = DateTime.Parse("2003-09-01")
                },
                new Student {
                    firstName = "Nino", lastName = "Olivetto", dateEnrollment = DateTime.Parse("2005-09-01")
                }
            };

            foreach (Student s in students)
            {
                context.students.Add(s);
            }
            context.SaveChanges();



            var instructors = new Instructor[]
            {
                new Instructor {
                    firstName = "Kim", lastName = "Abercrombie", hireDate = DateTime.Parse("1995-03-11")
                },
                new Instructor {
                    firstName = "Fadi", lastName = "Fakhouri", hireDate = DateTime.Parse("2002-07-06")
                },
                new Instructor {
                    firstName = "Roger", lastName = "Harui", hireDate = DateTime.Parse("1998-07-01")
                },
                new Instructor {
                    firstName = "Candace", lastName = "Kapoor", hireDate = DateTime.Parse("2001-01-15")
                },
                new Instructor {
                    firstName = "Roger", lastName = "Zheng", hireDate = DateTime.Parse("2004-02-12")
                }
            };

            foreach (Instructor i in instructors)
            {
                context.instructors.Add(i);
            }
            context.SaveChanges();



            var departments = new Department[]
            {
                new Department {
                    departName      = "English", budget = 350000,
                    departStartDate = DateTime.Parse("2007-09-01"),
                    instructorId    = instructors.Single(i => i.lastName == "Abercrombie").id
                },
                new Department {
                    departName      = "Mathematics", budget = 100000,
                    departStartDate = DateTime.Parse("2007-09-01"),
                    instructorId    = instructors.Single(i => i.lastName == "Fakhouri").id
                },
                new Department {
                    departName      = "Engineering", budget = 350000,
                    departStartDate = DateTime.Parse("2007-09-01"),
                    instructorId    = instructors.Single(i => i.lastName == "Harui").id
                },
                new Department {
                    departName      = "Economics", budget = 100000,
                    departStartDate = DateTime.Parse("2007-09-01"),
                    instructorId    = instructors.Single(i => i.lastName == "Kapoor").id
                }
            };

            foreach (Department d in departments)
            {
                context.departments.Add(d);
            }
            context.SaveChanges();



            var courses = new Course[]
            {
                new Course {
                    courseId     = 1050, courseTitle = "Chemistry", credit = 3,
                    departmentId = departments.Single(s => s.departName == "Engineering").departmentId
                },
                new Course {
                    courseId     = 4022, courseTitle = "Microeconomics", credit = 3,
                    departmentId = departments.Single(s => s.departName == "Economics").departmentId
                },
                new Course {
                    courseId     = 4041, courseTitle = "Macroeconomics", credit = 3,
                    departmentId = departments.Single(s => s.departName == "Economics").departmentId
                },
                new Course {
                    courseId     = 1045, courseTitle = "Calculus", credit = 4,
                    departmentId = departments.Single(s => s.departName == "Mathematics").departmentId
                },
                new Course {
                    courseId     = 3141, courseTitle = "Trigonometry", credit = 4,
                    departmentId = departments.Single(s => s.departName == "Mathematics").departmentId
                },
                new Course {
                    courseId     = 2021, courseTitle = "Composition", credit = 3,
                    departmentId = departments.Single(s => s.departName == "English").departmentId
                },
                new Course {
                    courseId     = 2042, courseTitle = "Literature", credit = 4,
                    departmentId = departments.Single(s => s.departName == "English").departmentId
                }
            };

            foreach (Course c in courses)
            {
                context.courses.Add(c);
            }
            context.SaveChanges();

            var officeAssignments = new OfficeAssignment[]
            {
                new OfficeAssignment {
                    instructorId = instructors.Single(i => i.lastName == "Fakhouri").id,
                    location     = "Smith 17"
                },
                new OfficeAssignment {
                    instructorId = instructors.Single(i => i.lastName == "Harui").id,
                    location     = "Gowan 27"
                },
                new OfficeAssignment {
                    instructorId = instructors.Single(i => i.lastName == "Kapoor").id,
                    location     = "Thompson 304"
                },
            };

            foreach (OfficeAssignment o in officeAssignments)
            {
                context.officeAssignments.Add(o);
            }
            context.SaveChanges();


            var courseInstructors = new CourseAssignment[]
            {
                new CourseAssignment {
                    courseId     = courses.Single(c => c.courseTitle == "Chemistry").courseId,
                    instructorId = instructors.Single(i => i.lastName == "Kapoor").id
                },
                new CourseAssignment {
                    courseId     = courses.Single(c => c.courseTitle == "Chemistry").courseId,
                    instructorId = instructors.Single(i => i.lastName == "Harui").id
                },
                new CourseAssignment {
                    courseId     = courses.Single(c => c.courseTitle == "Microeconomics").courseId,
                    instructorId = instructors.Single(i => i.lastName == "Zheng").id
                },
                new CourseAssignment {
                    courseId     = courses.Single(c => c.courseTitle == "Macroeconomics").courseId,
                    instructorId = instructors.Single(i => i.lastName == "Zheng").id
                },
                new CourseAssignment {
                    courseId     = courses.Single(c => c.courseTitle == "Calculus").courseId,
                    instructorId = instructors.Single(i => i.lastName == "Fakhouri").id
                },
                new CourseAssignment {
                    courseId     = courses.Single(c => c.courseTitle == "Trigonometry").courseId,
                    instructorId = instructors.Single(i => i.lastName == "Harui").id
                },
                new CourseAssignment {
                    courseId     = courses.Single(c => c.courseTitle == "Composition").courseId,
                    instructorId = instructors.Single(i => i.lastName == "Abercrombie").id
                },
                new CourseAssignment {
                    courseId     = courses.Single(c => c.courseTitle == "Literature").courseId,
                    instructorId = instructors.Single(i => i.lastName == "Abercrombie").id
                },
            };

            foreach (CourseAssignment ci in courseInstructors)
            {
                context.courseAssignments.Add(ci);
            }
            context.SaveChanges();


            var enrollments = new Enrollment[]
            {
                new Enrollment {
                    studentId = students.Single(s => s.lastName == "Alexander").id,
                    courseId  = courses.Single(c => c.courseTitle == "Chemistry").courseId,
                    grade     = Enrollment.Grade.A
                },
                new Enrollment {
                    studentId = students.Single(s => s.lastName == "Alexander").id,
                    courseId  = courses.Single(c => c.courseTitle == "Microeconomics").courseId,
                    grade     = Enrollment.Grade.C
                },
                new Enrollment {
                    studentId = students.Single(s => s.lastName == "Alexander").id,
                    courseId  = courses.Single(c => c.courseTitle == "Macroeconomics").courseId,
                    grade     = Enrollment.Grade.B
                },
                new Enrollment {
                    studentId = students.Single(s => s.lastName == "Alonso").id,
                    courseId  = courses.Single(c => c.courseTitle == "Calculus").courseId,
                    grade     = Enrollment.Grade.B
                },
                new Enrollment {
                    studentId = students.Single(s => s.lastName == "Alonso").id,
                    courseId  = courses.Single(c => c.courseTitle == "Trigonometry").courseId,
                    grade     = Enrollment.Grade.B
                },
                new Enrollment {
                    studentId = students.Single(s => s.lastName == "Alonso").id,
                    courseId  = courses.Single(c => c.courseTitle == "Composition").courseId,
                    grade     = Enrollment.Grade.B
                },
                new Enrollment {
                    studentId = students.Single(s => s.lastName == "Anand").id,
                    courseId  = courses.Single(c => c.courseTitle == "Chemistry").courseId,
                    grade     = Enrollment.Grade.D
                },
                new Enrollment {
                    studentId = students.Single(s => s.lastName == "Anand").id,
                    courseId  = courses.Single(c => c.courseTitle == "Microeconomics").courseId,
                    grade     = Enrollment.Grade.D
                },
                new Enrollment {
                    studentId = students.Single(s => s.lastName == "Barzdukas").id,
                    courseId  = courses.Single(c => c.courseTitle == "Chemistry").courseId,
                    grade     = Enrollment.Grade.B
                },
                new Enrollment {
                    studentId = students.Single(s => s.lastName == "Li").id,
                    courseId  = courses.Single(c => c.courseTitle == "Composition").courseId,
                    grade     = Enrollment.Grade.F
                },
                new Enrollment {
                    studentId = students.Single(s => s.lastName == "Justice").id,
                    courseId  = courses.Single(c => c.courseTitle == "Literature").courseId,
                    grade     = Enrollment.Grade.B
                }
            };

            foreach (Enrollment e in enrollments)
            {
                var enrollmentDb = context.enrollments.Where(
                    s =>
                    s.student.id == e.studentId &&
                    s.course.courseId == e.courseId
                    ).SingleOrDefault();

                if (enrollmentDb == null)
                {
                    context.enrollments.Add(e);
                }
            }
            context.SaveChanges();
        }        //End of class