コード例 #1
0
ファイル: VODContext.cs プロジェクト: shabbirh/VideoOnDemand3
        public void SeedMembershipData()
        {
            #region Lorem Ipsum - Dummy Data
            var description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.";
            #endregion

            #region Fetch a User
            var email  = "[email protected]";
            var userId = string.Empty;

            if (Users.Any(r => r.Email.Equals(email)))
            {
                userId = Users.First(r => r.Email.Equals(email)).Id;
            }
            else
            {
                return;
            }
            #endregion

            #region Add Instructors if they don't already exist
            if (!Instructors.Any())
            {
                var instructors = new List <Instructor>
                {
                    new Instructor {
                        Name        = "John Doe",
                        Description = description.Substring(20, 50),
                        Thumbnail   = "/images/Ice-Age-Scrat-icon.png"
                    },
                    new Instructor {
                        Name        = "Jane Doe",
                        Description = description.Substring(30, 40),
                        Thumbnail   = "/images/Ice-Age-Scrat-icon.png"
                    }
                };
                Instructors.AddRange(instructors);
                SaveChanges();
            }
            if (Instructors.Count() < 2)
            {
                return;
            }
            #endregion

            #region Add Courses if they don't already exist
            if (!Courses.Any())
            {
                var instructorId1 = Instructors.First().Id;
                var instructorId2 = Instructors.Skip(1).FirstOrDefault().Id;

                var courses = new List <Course>
                {
                    new Course {
                        InstructorId    = instructorId1,
                        Title           = "Course 1",
                        Description     = description,
                        ImageUrl        = "/images/course1.jpg",
                        MarqueeImageUrl = "/images/laptop.jpg"
                    },
                    new Course {
                        InstructorId    = instructorId2,
                        Title           = "Course 2",
                        Description     = description,
                        ImageUrl        = "/images/course2.jpg",
                        MarqueeImageUrl = "/images/laptop.jpg"
                    },
                    new Course {
                        InstructorId    = instructorId1,
                        Title           = "Course 3",
                        Description     = description,
                        ImageUrl        = "/images/course3.jpg",
                        MarqueeImageUrl = "/images/laptop.jpg"
                    }
                };
                Courses.AddRange(courses);
                SaveChanges();
            }
            if (Courses.Count() < 3)
            {
                return;
            }
            #endregion

            #region Fetch Course ids if any courses exists
            var courseId1 = Courses.First().Id;
            var courseId2 = Courses.Skip(1).FirstOrDefault().Id;
            var courseId3 = Courses.Skip(2).FirstOrDefault().Id;
            #endregion

            #region Add UserCourses connections if they don't already exist
            if (!UserCourses.Any())
            {
                UserCourses.Add(new UserCourse {
                    UserId = userId, CourseId = courseId1
                });
                UserCourses.Add(new UserCourse {
                    UserId = userId, CourseId = courseId2
                });
                UserCourses.Add(new UserCourse {
                    UserId = userId, CourseId = courseId3
                });

                SaveChanges();
            }
            if (UserCourses.Count() < 3)
            {
                return;
            }
            #endregion

            #region Add Modules if they don't already exist
            if (!Modules.Any())
            {
                var modules = new List <Module>
                {
                    new Module {
                        Course = Find <Course>(courseId1), Title = "Modeule 1"
                    },
                    new Module {
                        Course = Find <Course>(courseId1), Title = "Modeule 2"
                    },
                    new Module {
                        Course = Find <Course>(courseId2), Title = "Modeule 3"
                    }
                };
                Modules.AddRange(modules);
                SaveChanges();
            }
            if (Modules.Count() < 3)
            {
                return;
            }
            #endregion

            #region Fetch Module ids if any modules exist
            var module1 = Modules.First();
            var module2 = Modules.Skip(1).FirstOrDefault();
            var module3 = Modules.Skip(2).FirstOrDefault();
            #endregion

            #region Add Videos if they don't already exist
            if (!Videos.Any())
            {
                var videos = new List <Video>
                {
                    new Video {
                        ModuleId    = module1.Id, CourseId = module1.CourseId,
                        Title       = "Video 1 Title",
                        Description = description.Substring(1, 35),
                        Duration    = 50, Thumbnail = "/images/video1.jpg",
                        Url         = "https://www.youtube.com/embed/BJFyzpBcaCY"
                    },
                    new Video {
                        ModuleId    = module1.Id, CourseId = module1.CourseId,
                        Title       = "Video 2 Title",
                        Description = description.Substring(5, 35),
                        Duration    = 45, Thumbnail = "/images/video2.jpg",
                        Url         = "https://www.youtube.com/embed/BJFyzpBcaCY"
                    },
                    new Video {
                        ModuleId    = module1.Id, CourseId = module1.CourseId,
                        Title       = "Video 3 Title",
                        Description = description.Substring(10, 35),
                        Duration    = 41, Thumbnail = "/images/video3.jpg",
                        Url         = "https://www.youtube.com/embed/BJFyzpBcaCY"
                    },
                    new Video {
                        ModuleId    = module3.Id, CourseId = module3.CourseId,
                        Title       = "Video 4 Title",
                        Description = description.Substring(15, 35),
                        Duration    = 41, Thumbnail = "/images/video4.jpg",
                        Url         = "https://www.youtube.com/embed/BJFyzpBcaCY"
                    },
                    new Video {
                        ModuleId    = module2.Id, CourseId = module2.CourseId,
                        Title       = "Video 5 Title",
                        Description = description.Substring(20, 35),
                        Duration    = 42, Thumbnail = "/images/video5.jpg",
                        Url         = "https://www.youtube.com/embed/BJFyzpBcaCY"
                    }
                };
                Videos.AddRange(videos);
                SaveChanges();
            }
            #endregion

            #region Add Downloads if they don't already exist
            if (!Downloads.Any())
            {
                var downloads = new List <Download>
                {
                    new Download {
                        ModuleId = module1.Id, CourseId = module1.CourseId,
                        Title    = "ADO.NET 1 (PDF)", Url = "https://some-url"
                    },

                    new Download {
                        ModuleId = module1.Id, CourseId = module1.CourseId,
                        Title    = "ADO.NET 2 (PDF)", Url = "https://some-url"
                    },

                    new Download {
                        ModuleId = module3.Id, CourseId = module3.CourseId,
                        Title    = "ADO.NET 1 (PDF)", Url = "https://some-url"
                    }
                };

                Downloads.AddRange(downloads);
                SaveChanges();
            }
            #endregion
        }
コード例 #2
0
        public void SeedMembershipData()
        {
            var description = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. " +
                              "Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus " +
                              "et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, " +
                              "pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, " +
                              "aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. " +
                              "Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. " +
                              "Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. " +
                              "Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. " +
                              "Quisque rutrum. ";
            var email  = "[email protected]";
            var userId = string.Empty;

            if (Users.Any(r => r.Email.Equals(email)))
            {
                userId = Users.First(r => r.Email.Equals(email)).Id;
            }
            else
            {
                return;
            }

            if (!Instructors.Any())
            {
                var instructors = new List <Instructor>
                {
                    new Instructor
                    {
                        Name        = "John Doe",
                        Description = description.Substring(20, 50),
                        Thumbnail   = "/images/Ice-Age-Scrat-icon.png"
                    },
                    new Instructor
                    {
                        Name        = "Jane Doe",
                        Description = description.Substring(30, 40),
                        Thumbnail   = "/images/Ice-Age-Scrat-icon.png"
                    }
                };
                Instructors.AddRange(instructors);
                SaveChanges();
            }

            if (Instructors.Count() < 2)
            {
                return;
            }

            if (!Courses.Any())
            {
                var instructorId1 = Instructors.First().Id;
                var instructorId2 = Instructors.Skip(1).FirstOrDefault().Id;

                var courses = new List <Course>
                {
                    new Course {
                        InstructorId    = instructorId1,
                        Title           = "Course 1",
                        Description     = description,
                        ImageUrl        = "/images/course1.jpg",
                        MarqueeImageUrl = "/images/laptop.jpg"
                    },
                    new Course {
                        InstructorId    = instructorId2,
                        Title           = "Course 2",
                        Description     = description,
                        ImageUrl        = "/images/course2.jpg",
                        MarqueeImageUrl = "/images/laptop.jpg"
                    },
                    new Course {
                        InstructorId    = instructorId1,
                        Title           = "Course 3",
                        Description     = description,
                        ImageUrl        = "/images/course3.jpg",
                        MarqueeImageUrl = "/images/laptop.jpg"
                    }
                };
                Courses.AddRange(courses);
                SaveChanges();
            }
            if (Courses.Count() < 3)
            {
                return;
            }

            var courseId1 = Courses.First().Id;
            var courseId2 = Courses.Skip(1).FirstOrDefault().Id;
            var courseId3 = Courses.Skip(2).FirstOrDefault().Id;

            if (!UserCourses.Any())
            {
                if (!courseId1.Equals(int.MinValue))
                {
                    UserCourses.Add(new UserCourse {
                        UserId = userId, CourseId = courseId1
                    });
                }

                if (!courseId2.Equals(int.MinValue))
                {
                    UserCourses.Add(new UserCourse {
                        UserId = userId, CourseId = courseId2
                    });
                }

                if (!courseId3.Equals(int.MinValue))
                {
                    UserCourses.Add(new UserCourse {
                        UserId = userId, CourseId = courseId3
                    });
                }

                SaveChanges();
            }

            if (UserCourses.Count() < 3)
            {
                return;
            }

            if (!Modules.Any())
            {
                var modules = new List <Module>
                {
                    new Module {
                        Course = Find <Course>(courseId1), Title = "Module 1"
                    },
                    new Module {
                        Course = Find <Course>(courseId2), Title = "Module 2"
                    },
                    new Module {
                        Course = Find <Course>(courseId3), Title = "Module 3"
                    }
                };
                Modules.AddRange(modules);
                SaveChanges();
            }

            if (Modules.Count() < 3)
            {
                return;
            }

            var module1 = Modules.First();
            var module2 = Modules.Skip(1).FirstOrDefault();
            var module3 = Modules.Skip(2).FirstOrDefault();

            if (!Videos.Any())
            {
                var videos = new List <Video> {
                    new Video {
                        ModuleId    = module1.Id,
                        CourseId    = courseId1,
                        Title       = "Video 1 Title",
                        Description = description.Substring(1, 35),
                        Duration    = 50, Thumbnail = "/images/video1.jpg",
                        Url         = "https://www.youtube.com/embed/BJFyzpBcaCY"
                    },
                    new Video {
                        ModuleId    = module2.Id,
                        CourseId    = courseId2,
                        Title       = "Video 2 Title",
                        Description = description.Substring(5, 35),
                        Duration    = 45, Thumbnail = "/images/video2.jpg",
                        Url         = "https://www.youtube.com/embed/BJFyzpBcaCY"
                    },
                    new Video {
                        ModuleId    = module3.Id,
                        CourseId    = courseId3,
                        Title       = "Video 3 Title",
                        Description = description.Substring(10, 35),
                        Duration    = 41, Thumbnail = "/images/video3.jpg",
                        Url         = "https://www.youtube.com/embed/BJFyzpBcaCY"
                    },
                    new Video {
                        ModuleId    = module3.Id,
                        CourseId    = courseId2,
                        Title       = "Video 4 Title",
                        Description = description.Substring(15, 35),
                        Duration    = 41, Thumbnail = "/images/video4.jpg",
                        Url         = "https://www.youtube.com/embed/BJFyzpBcaCY"
                    },
                    new Video {
                        ModuleId    = module2.Id,
                        CourseId    = courseId1,
                        Title       = "Video 5 Title",
                        Description = description.Substring(20, 35),
                        Duration    = 42, Thumbnail = "/images/video5.jpg",
                        Url         = "https://www.youtube.com/embed/BJFyzpBcaCY"
                    }
                };
                Videos.AddRange(videos);
                SaveChanges();
            }
            if (!Downloads.Any())
            {
                var downloads = new List <Download>
                {
                    new Download {
                        ModuleId = module1.Id, CourseId = courseId1,
                        Title    = "ADO.NET 1 (PDF)", Url = "https://some-url"
                    },

                    new Download {
                        ModuleId = module2.Id, CourseId = courseId2,
                        Title    = "ADO.NET 2 (PDF)", Url = "https://some-url"
                    },

                    new Download {
                        ModuleId = module3.Id, CourseId = courseId3,
                        Title    = "ADO.NET 1 (PDF)", Url = "https://some-url"
                    }
                };

                Downloads.AddRange(downloads);
                SaveChanges();
            }
        }
コード例 #3
0
        public void SeedMembershipData()
        {
            var description1 =
                "C# is a simple, modern, general-purpose, object-oriented programming language" +
                " developed by Microsoft within its .NET initiative led by Anders Hejlsberg.";
            var description2 = "JavaScript is a fun and flexible programming language." +
                               " It's one of the core technologies of web development" +
                               " and can be used on both the front-end and the ..";
            var description3 = "HTML is the World Wide Web's core markup language. Originally," +
                               " HTML was primarily designed as a language for semantically describing ";

            #region Fetch a User

            var email = "a.b@c";
            var userId = string.Empty;

            if (Users.Any(r => r.Email.Equals(email)))
                userId = Users.First(r => r.Email.Equals(email)).Id;
            else
                return;

            #endregion Fetch a User

            #region Add Instructors if they don't already exist

            if (!Instructors.Any())
            {
                var instructors = new List<Instructor>
                {
                    new Instructor
                    {
                        Name = "Garad Gafadi",
                        Description =
                            "Garad Gafadi is a software developer and a future co-founder of OneLove Corporation.",

                        Thumbnail = "/images/avatar2.jpg"
                    },
                    new Instructor
                    {
                        Name = "Adam Ganays",
                        Description = "Adam is a software developer and a future co-founder of OneLove Corporation.",
                        Thumbnail = " /Images/avatar.png"
                    },
                    new Instructor
                    {
                        Name = "Lovisa Jonsson",
                        Description = "Adam is a software developer and a future co-founder of OneLove Corporation.",
                        Thumbnail = " /Images/avatar.png"
                    }
                };
                Instructors.AddRange(instructors);
                SaveChanges();
            }

            if (Instructors.Count() < 3) return;

            #endregion Add Instructors if they don't already exist

            #region Add Courses if they don't already exist

            if (!Courses.Any())
            {
                var instructorId1 = Instructors.First().Id;
                var instructorId2 = Instructors.Skip(1).FirstOrDefault().Id;
                var instructorId3 = Instructors.Skip(2).FirstOrDefault().Id;

                var courses = new List<Course>
                {
                    new Course
                    {
                        InstructorId = instructorId1,
                        Title = "C#",
                        Description = description1,
                        ImageUrl = "/Images/cours1.jpg",
                        MarqueeImageUrl = "/Images/laptop.jpg"
                    },
                    new Course
                    {
                        InstructorId = instructorId2,
                        Title = "JavaScript",
                        Description = description2,
                        ImageUrl = "/Images/cours2.png",
                        MarqueeImageUrl = "/images/laptop.jpg"
                    },
                    new Course
                    {
                        InstructorId = instructorId3,
                        Title = "HMTL",
                        Description = description3,
                        ImageUrl = "/Images/cours3.png",
                        MarqueeImageUrl = "/Images/laptop.jpg"
                    }
                };
                Courses.AddRange(courses);
                SaveChanges();
            }

            if (Courses.Count() < 3) return;

            #endregion Add Courses if they don't already exist

            #region Fetch Course ids if any courses exists

            var courseId1 = Courses.First().Id;
            var courseId2 = Courses.Skip(1).FirstOrDefault().Id;
            var courseId3 = Courses.Skip(2).FirstOrDefault().Id;

            #endregion Fetch Course ids if any courses exists

            #region Add UserCourses connections if they don't already exist

            if (!UserCourses.Any())
            {
                UserCourses.Add(new UserCourse {UserId = userId, CourseId = courseId1});
                UserCourses.Add(new UserCourse {UserId = userId, CourseId = courseId2});
                UserCourses.Add(new UserCourse {UserId = userId, CourseId = courseId3});

                SaveChanges();
            }

            if (UserCourses.Count() < 3) return;

            #endregion Add UserCourses connections if they don't already exist

            #region Add Modules if they don't already exist

            if (!Modules.Any())
            {
                var modules = new List<Module>
                {
                    new Module
                    {
                        Course = Find<Course>(courseId1), Title = "Module 1"
                    },

                    new Module
                    {
                        Course = Find<Course>(courseId2), Title = "Module 2"
                    },
                    new Module
                    {
                        Course = Find<Course>(courseId3), Title = "Module 3"
                    }
                };
                Modules.AddRange(modules);
                SaveChanges();
            }

            if (Modules.Count() < 3) return;

            #endregion Add Modules if they don't already exist

            #region Fetch Module ids if any modules exist

            var moduleId1 = Modules.First().Id;
            var moduleId2 = Modules.Skip(1).FirstOrDefault().Id;
            var moduleId3 = Modules.Skip(2).FirstOrDefault().Id;

            #endregion Fetch Module ids if any modules exist

            #region Add Videos if they don't already exist

            if (!Videos.Any())
            {
                var video = new List<Video>
                {
                    new Video
                    {
                        ModuleId = moduleId1, CourseId = courseId1, Title = "C# Toturial1",
                        Description = description1.Substring(1, 100),
                        Thumbnail = "/images/video1.jpg",
                        Duration = 14, Url = "https://youtu.be/yK6zlTVqWzo"
                    },

                    new Video
                    {
                        ModuleId = moduleId1, CourseId = courseId1, Title = "JavaScript For Beginers",
                        Description = description2.Substring(1, 50),
                        Thumbnail = "/images/video2.jpg",
                        Duration = 48, Url = "https://www.youtube.com/watch?v=qv6ZflueASY"
                    },

                    new Video
                    {
                        ModuleId = moduleId1, CourseId = courseId1, Title = "HTML For Beginers",
                        Description = description3.Substring(1, 80),
                        Thumbnail = "/images/video3.jpg",
                        Duration = 12, Url = "https://youtu.be/bWPMSSsVdPk"
                    },

                    new Video
                    {
                        ModuleId = moduleId2, CourseId = courseId2, Title = "JavaScript For Beginers",
                        Description = description2.Substring(1, 50),
                        Thumbnail = "/images/video2.jpg",
                        Duration = 48, Url = "https://youtu.be/W6NZfCO5SIk"
                    },

                    new Video
                    {
                        ModuleId = moduleId2, CourseId = courseId2, Title = "HTML For Beginers",
                        Description = description3.Substring(1, 80),
                        Thumbnail = "/images/video3.jpg",
                        Duration = 12, Url = "https://youtu.be/bWPMSSsVdPk"
                    },
                    new Video
                    {
                        ModuleId = moduleId3, CourseId = courseId2, Title = "JavaScript For Beginers",
                        Description = description2.Substring(1, 50),
                        Thumbnail = "/images/video2.jpg",
                        Duration = 48, Url = "https://youtu.be/W6NZfCO5SIk"
                    },

                    new Video
                    {
                        ModuleId = moduleId3, CourseId = courseId2, Title = "HTML For Beginers",
                        Description = description3.Substring(1, 80),
                        Thumbnail = "/images/video3.jpg",
                        Duration = 12, Url = "https://youtu.be/bWPMSSsVdPk"
                    }
                };
                Videos.AddRange(video);
                SaveChanges();
            }

            #endregion Add Videos if they don't already exist

            #region Add Downloads if they don't already exist

            if (!Downloads.Any())
            {
                var downloads = new List<Download>
                {
                    new Download
                    {
                        ModuleId = moduleId1, CourseId = courseId1, Title = "C# Toturials (PDF)",
                        Url = "https://some-url"
                    },
                    new Download
                    {
                        ModuleId = moduleId1, CourseId = courseId1, Title = "JavaScript Toturials (PDF)",
                        Url = "https://some-url"
                    },
                    new Download
                    {
                        ModuleId = moduleId1, CourseId = courseId1, Title = "HTML Toturials (PDF)",
                        Url = "https://some-url"
                    },
                    new Download
                    {
                        ModuleId = moduleId1, CourseId = courseId2, Title = "JavaScript Toturials (PDF)",
                        Url = "https://some-url"
                    },
                    new Download
                    {
                        ModuleId = moduleId1, CourseId = courseId2, Title = "HTML Toturials (PDF)",
                        Url = "https://some-url"
                    },
                    new Download
                    {
                        ModuleId = moduleId1, CourseId = courseId3, Title = "JavaScript Toturials (PDF)",
                        Url = "https://some-url"
                    },
                    new Download
                    {
                        ModuleId = moduleId1, CourseId = courseId3, Title = "HTML Toturials (PDF)",
                        Url = "https://some-url"
                    }
                };

                Downloads.AddRange(downloads);
                SaveChanges();
            }

            #endregion Add Downloads if they don't already exist
        }