Beispiel #1
0
 private static OnlineCourse GetOnlineCourse(string courseName)
 {
     using (var ctx = new CoreModelContext())
     {
         return ctx.OnlineCourses.FirstOrDefault(c => c.Title == courseName);
     }
 }
Beispiel #2
0
 private static OnlineCourse GetOnlineCourse(string courseName)
 {
     using (var ctx = new CoreModelContext())
     {
         return(ctx.OnlineCourses.FirstOrDefault(c => c.Title == courseName));
     }
 }
Beispiel #3
0
 private static void UpdateCourse(Course course)
 {
     using (var ctx = new CoreModelContext())
     {
         ctx.Entry(course).State = course.Id == 0 ? EntityState.Added : EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Beispiel #4
0
 private static void DeleteCourse()
 {
     using (var ctx = new CoreModelContext())
     {
         var course = ctx.Courses.FirstOrDefault(c => c.Title == "Market Efficiency");
         ctx.Courses.Remove(course);
         ctx.SaveChanges();
     }
 }
Beispiel #5
0
 private static void DeleteCourse()
 {
     using (var ctx = new CoreModelContext())
     {
         var course = ctx.Courses.FirstOrDefault(c => c.Title == "Market Efficiency");
         ctx.Courses.Remove(course);
         ctx.SaveChanges();
     }
 }
Beispiel #6
0
 private static void GetCourses()
 {
     using (var ctx = new CoreModelContext())
     {
         Console.WriteLine("In Get Courses");
         var courses = ctx.OnlineCourses.ToList();
         foreach (var onlineCourse in courses)
         {
             Console.WriteLine("Course " + onlineCourse.Id);
         }
     }
 }
Beispiel #7
0
 private static void GetCourses()
 {
     using (var ctx = new CoreModelContext())
     {
         Console.WriteLine("In Get Courses");
         var courses = ctx.OnlineCourses.ToList();
         foreach (var onlineCourse in courses)
         {
             Console.WriteLine("Course " + onlineCourse.Id);
         }
     }
 }
Beispiel #8
0
        private static void InsertInstructorParking()
        {
            using (var ctx = new CoreModelContext())
            {
                var instructor = ctx.Instructors.First(i => i.LastName == "Li");
                instructor.AssignedParking = new AssignedParking()
                {
                    SpaceNumber = "PS 1"
                };

                ctx.SaveChanges();
            }
        }
Beispiel #9
0
        private static void GetInstructor()
        {
            using (var ctx = new CoreModelContext())
            {
                var query = ctx.Instructors.FirstOrDefault();
                if (query != null)
                {
                    var msg = string.Format("Instructor {0} : {1} {2} - Office at {3}", query.Id.ToString(),
                        query.FirstName, query.LastName, query.Office.Location);

                    Console.WriteLine(msg);
                }
            }
        }
Beispiel #10
0
        private static void GetInstructor()
        {
            using (var ctx = new CoreModelContext())
            {
                var query = ctx.Instructors.FirstOrDefault();
                if (query != null)
                {
                    var msg = string.Format("Instructor {0} : {1} {2} - Office at {3}", query.Id.ToString(),
                                            query.FirstName, query.LastName, query.Office.Location);

                    Console.WriteLine(msg);
                }
            }
        }
Beispiel #11
0
        private static void UpdateOnlineCourseUsingSetValue(Course course)
        {
            using (var ctx = new CoreModelContext())
            {
                //var entry = ctx.Courses.Where(c => c.Id == course.Id).FirstOrDefault();
                ctx.OnlineCourses.Load();
                var entry =
                    ctx.ChangeTracker.Entries <OnlineCourse>().FirstOrDefault(e => ((int)e.CurrentValues["Id"]) == course.Id);

                if (entry != null)
                {
                    entry.CurrentValues.SetValues(course); //Great way to use DTO objects to set only subset of properties without empty out other property values
                    ctx.SaveChanges();
                }
            }
        }
Beispiel #12
0
        private static void InsertDepartment()
        {
            using (var ctx = new CoreModelContext())
            {
                var department = new Department
                {
                    Name      = "Economy",
                    Budget    = 200000m,
                    StartDate = System.DateTime.Now,
                    Courses   = new List <Course>
                    {
                        new OnlineCourse()
                        {
                            Title       = "Micro Economy",
                            Credits     = 3,
                            Url         = "http://www.microeconomy.com",
                            Instructors =
                                new List <Instructor>()
                            {
                                new Instructor()
                                {
                                    FirstName = "Daniel",
                                    LastName  = "Li",
                                    Gender    = EGender.Male,
                                    Office    = new Office()
                                    {
                                        Location = "Building 5"
                                    }
                                }
                            }
                        }
                    }
                };

                if (ctx.Departments.Any(d => d.Name == "Economy") == false)
                {
                    Console.WriteLine("Insert new Department");
                    ctx.Departments.Add(department);
                    ctx.SaveChanges();
                    Console.WriteLine("End of Insert new Department");
                }
            }
        }
Beispiel #13
0
        private static void InsertCourse()
        {
            using (var ctx = new CoreModelContext())
            {
                var courseTitle = "Market Efficiency";

                var course = new OnSiteCourse()
                {
                    Title       = courseTitle,
                    Credits     = 2,
                    Department  = ctx.Departments.First(d => d.Name == "Economy"),
                    Instructors = new List <Instructor>()
                    {
                        //new Instructor()
                        //{
                        //    FirstName = "Jennifer",
                        //    LastName = "Lopez",
                        //    Gender = EGender.Female,
                        //    Office = new Office() {Location = "Building 1"}
                        //},
                        ctx.Instructors.First(i => i.LastName == "Lopez"),
                        ctx.Instructors.First(i => i.LastName == "Li")
                    },
                    Details = new Details()
                    {
                        DurationDays = 90, Location = "Building 5", Time = System.DateTime.Now
                    }
                };

                if (ctx.Courses.Any(c => c.Title == courseTitle) == false)
                {
                    Console.WriteLine("Insert new course " + courseTitle);
                    ctx.Courses.Add(course);
                    ctx.SaveChanges();
                    Console.WriteLine("Finish inserting new course " + courseTitle);
                }
            }
        }
Beispiel #14
0
        private static void InsertDepartment()
        {
            using (var ctx = new CoreModelContext())
            {
                var department = new Department
                {
                    Name = "Economy",
                    Budget = 200000m,
                    StartDate = System.DateTime.Now,
                    Courses = new List<Course>
                    {
                        new OnlineCourse()
                        {
                            Title = "Micro Economy",
                            Credits = 3,
                            Url = "http://www.microeconomy.com",
                            Instructors =
                                new List<Instructor>()
                                {
                                    new Instructor()
                                    {
                                        FirstName = "Daniel",
                                        LastName = "Li",
                                        Gender = EGender.Male,
                                        Office = new Office() {Location = "Building 5"}
                                    }
                                }
                        }
                    }
                };

                if (ctx.Departments.Any(d => d.Name == "Economy") == false)
                {
                    Console.WriteLine("Insert new Department");
                    ctx.Departments.Add(department);
                    ctx.SaveChanges();
                    Console.WriteLine("End of Insert new Department");
                }
            }
        }
Beispiel #15
0
 private static void UpdateCourse(Course course)
 {
     using (var ctx = new CoreModelContext())
     {
         ctx.Entry(course).State = course.Id == 0 ? EntityState.Added : EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Beispiel #16
0
        private static void UpdateOnlineCourseUsingSetValue(Course course)
        {
            using (var ctx = new CoreModelContext())
            {
                //var entry = ctx.Courses.Where(c => c.Id == course.Id).FirstOrDefault();
                ctx.OnlineCourses.Load();
                var entry =
                    ctx.ChangeTracker.Entries<OnlineCourse>().FirstOrDefault(e => ((int)e.CurrentValues["Id"]) == course.Id);

                if (entry != null)
                {
                    entry.CurrentValues.SetValues(course); //Great way to use DTO objects to set only subset of properties without empty out other property values
                    ctx.SaveChanges();
                }
            }
        }
Beispiel #17
0
        private static void InsertCourse()
        {
            using (var ctx = new CoreModelContext())
            {
                var courseTitle = "Market Efficiency";

                var course = new OnSiteCourse()
                {
                    Title = courseTitle,
                    Credits = 2,
                    Department = ctx.Departments.First(d => d.Name == "Economy"),
                    Instructors = new List<Instructor>()
                    {
                        //new Instructor()
                        //{
                        //    FirstName = "Jennifer",
                        //    LastName = "Lopez",
                        //    Gender = EGender.Female,
                        //    Office = new Office() {Location = "Building 1"}
                        //},
                        ctx.Instructors.First(i => i.LastName == "Lopez"),
                        ctx.Instructors.First(i => i.LastName == "Li")
                    },
                    Details = new Details() { DurationDays = 90, Location = "Building 5", Time = System.DateTime.Now }
                };

                if (ctx.Courses.Any(c => c.Title == courseTitle) == false)
                {
                    Console.WriteLine("Insert new course " + courseTitle);
                    ctx.Courses.Add(course);
                    ctx.SaveChanges();
                    Console.WriteLine("Finish inserting new course " + courseTitle);
                }
            }
        }
Beispiel #18
0
        private static void InsertInstructorParking()
        {
            using (var ctx = new CoreModelContext())
            {
                var instructor = ctx.Instructors.First(i => i.LastName == "Li");
                instructor.AssignedParking = new AssignedParking() { SpaceNumber = "PS 1" };

                ctx.SaveChanges();
            }
        }