Пример #1
0
        public void SeedStudentCourses()
        {
            int courseCount = db.Courses.Count();

            if (courseCount <= 2)
            {
                return;
            }

            var studentCount = db.Students.Count();

            for (int i = 1; i <= studentCount; i++)
            {
                var student = db.Students.First(c => c.StudentId == i);

                var coursesCount = randomGenerator.GetRandomInteger(1, 5);
                for (int j = 0; j < coursesCount; j++)
                {
                    var randCourseId = randomGenerator.GetRandomInteger(1, courseCount);
                    var course       = db.Courses.First(c => c.CourseId == randCourseId);

                    student.Courses.Add(course);
                }
            }

            db.SaveChanges();
        }
Пример #2
0
        private static void Seed(StudentSystemContext db)
        {
            List <Student> students = new List <Student>
            {
                new Student()
                {
                    Name         = "Pesho",
                    PhoneNumber  = "0123456789",
                    RegisteredOn = new DateTime(2003, 12, 23),
                    Birthday     = new DateTime(2000, 11, 23)
                },
                new Student()
                {
                    Name         = "Georgi",
                    PhoneNumber  = "0123456786",
                    RegisteredOn = new DateTime(2004, 11, 18),
                    Birthday     = new DateTime(1999, 5, 1)
                },
                new Student()
                {
                    Name         = "Stanimir",
                    PhoneNumber  = "0012345678",
                    RegisteredOn = new DateTime(2017, 1, 3),
                    Birthday     = new DateTime(1985, 03, 15)
                },
            };

            db.Students.AddRange(students);



            db.SaveChanges();
        }
Пример #3
0
        private void SeedStudents(StudentSystemContext context, Random random)
        {
            string[] names =
            {
                "Maria", "Ivan", "Petur", "Viktoria", "Aishe", "Nakov", "Georgi", "General Radev",
                "Donald Trump"
            };

            string[] phoneNumbers =
            {
                "+359886000000", "+359886000001", "+359886000002", "+359886000003", "+359886111111",
                "+35952123456"
            };

            for (int i = 0; i < 10; i++)
            {
                context.Students.AddOrUpdate(student => student.Name,
                                             new Student()
                {
                    Name         = names[random.Next(names.Length)],
                    PhoneNumber  = phoneNumbers[random.Next(phoneNumbers.Length)],
                    RegisteredOn = DateTime.Now,
                    BirthDay     = new DateTime(1920, 5, 7).AddDays(5 * i)
                });
            }

            context.SaveChanges();
        }
Пример #4
0
        private void SeedHomeworks(StudentSystemContext context, Random random)
        {
            using (var reader = new StreamReader("D:/DB Advanced/EntityFrameWork_Relations/StudentSystem/resources/content.txt"))
            {
                while (true)
                {
                    string line = reader.ReadLine();

                    if (line == null)
                    {
                        break;
                    }

                    string[] data = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    context.Homeworks.AddOrUpdate(homework => homework.Content,
                                                  new Homework()
                    {
                        Content        = data[random.Next(data.Length)],
                        ContentType    = (ContentType)random.Next(0, 3),
                        SubmissionDate = DateTime.Now.AddDays(15),
                    });
                }
            }

            context.SaveChanges();
        }
Пример #5
0
        private static void Seed(StudentSystemContext db)
        {
            var students = new[]
            {
                new Student("Pesho Nakov", "0888888888", DateTime.Parse("2014/03/03"), DateTime.Parse("1990/03/03")),
                new Student("Gosho Peshov", "0899999999", DateTime.Parse("2015/06/03"), DateTime.Parse("1988/03/10")),
                new Student("Mimi Kapsuzova", "0877777777", DateTime.Parse("2016/06/27"), DateTime.Parse("1997/12/27")),
                new Student("Ani Lebedkova", "0878787878", DateTime.Parse("2013/09/11"), DateTime.Parse("1985/08/01")),
                new Student("Kolyo Mvrudiev", "0898989898", DateTime.Parse("2015/10/07"), DateTime.Parse("1990/02/06"))
            };

            db.Students.AddRange(students);

            var courses = new[]
            {
                new Course("Kachestveni narkotici", "Ey sq sh'e gi nauchite!", "2017/01/10", "2017/06/10", 3475.45m),
                new Course("Prostituciq", "Nachalen kurs za kurvi i svodnici. (Kontraceptivite sa za vasha smetka)", "2017/02/15", "2017/02/26", 475.99m),
                new Course("Smurtonosno orujie", "Nay-dobriq kurs za boravene s orujie na ulicata! Budi s nas, ostani jiv", "2017/01/10", "2018/01/10", 8975.90m),
                new Course("Drebna prestupnost ili kak da pravim pari ot prosqci", "Razkriyte taynite na drebnata organizirana prestupnost", "2017/09/12", "2017/12/10", 5175.19m),
            };

            db.Courses.AddRange(courses);

            db.SaveChanges();
        }
        static void Main(string[] args)
        {
            StudentSystemContext context = new StudentSystemContext();

            var firstMark = new Mark()
            {
                Subject = "Math", Value = 6
            };
            var secondMark = new Mark()
            {
                Subject = "FBS", Value = 5
            };


            var student = new Student()
            {
                FirstName = "Peter", LastName = "Petrov", Age = 20, Grade = 2
            };

            student.Marks.Add(firstMark);
            student.Marks.Add(secondMark);

            var school = new School()
            {
                Name = "PMG", Location = "Sofia"
            };

            school.Students.Add(student);

            context.Schools.Add(school);

            context.SaveChanges();
        }
Пример #7
0
        private static void SeedResources(StudentSystemContext context)
        {
            Resource[] resources =
            {
                new Resource
                {
                    Name         = "Video for programmers",
                    ResourceType = ResourceType.Video,
                    Url          = "comming soon",
                    CourseId     = 1
                },
                new Resource
                {
                    Name         = "Presentation for programmers",
                    ResourceType = ResourceType.Presentation,
                    Url          = "comming soon",
                    CourseId     = 1
                },
                new Resource
                {
                    Name         = "Presentation for new programmers",
                    ResourceType = ResourceType.Presentation,
                    Url          = "comming soon",
                    CourseId     = 1
                }
            };

            context.Resources.AddRange(resources);
            context.SaveChanges();
        }
        internal static void InitialResourceSeed(StudentSystemContext context)
        {
            Random random = new Random();

            var resourceNames = new string[]
            {
                "Type of Managers",
                "Human Resources",
                "How to create teams",
                "The future of entrepreneurship",
                "Management of 21 century"
            };

            for (int i = 0; i < resourceNames.Length; i++)
            {
                context.Resources.Add(new Resource()
                {
                    Name         = resourceNames[i],
                    Url          = "managers.com",
                    ResourceType = Enum.Parse <ResourceType>(random.Next(1, 4).ToString()),
                    CourseId     = random.Next(1, 5)
                });

                context.SaveChanges();
            }
        }
Пример #9
0
        internal static void InitialCourseSeed(StudentSystemContext context)
        {
            Random random = new Random();

            var courseNames = new string[]
            {
                "Basics of Management",
                "Management Skills",
                "Logistics",
                "Team Management",
                "Industrial Relationships"
            };

            for (int i = 0; i < courseNames.Length; i++)
            {
                context.Courses.Add(new Course()
                {
                    Name      = courseNames[i],
                    StartDate = DateTime.Now.AddDays(random.Next(1, 10)),
                    EndDate   = DateTime.Now.AddDays(random.Next(10, 20)),
                    Price     = 1 + ((decimal)random.NextDouble() * (random.Next(2, 100) - 1))
                });

                context.SaveChanges();
            }
        }
Пример #10
0
        static void Main()
        {
            Database.SetInitializer(
                new MigrateDatabaseToLatestVersion
                <StudentSystemContext, Configuration>());

            var db = new StudentSystemContext();

            var student = new Student {
                Name = "Denkata", Number = "21313"
            };

            db.Students.Add(student);

            var courseStudents = new List <Student>();

            courseStudents.Add(student);
            var course = new Course {
                Name = "JS Apps", Description = "Cool", Materials = "A lot", Students = courseStudents
            };

            db.Courses.Add(course);

            db.SaveChanges();
        }
Пример #11
0
        public static void Main()
        {
            Database.SetInitializer
                (new MigrateDatabaseToLatestVersion <StudentSystemContext, Configuration>());

            var dbConnection = new StudentSystemContext();

            using (dbConnection)
            {
                // Add course to Pesho.
                var studentPesho = dbConnection.Students.Find(1);
                studentPesho.Courses.Add(dbConnection.Courses.Find(3));
                studentPesho.Courses.Add(dbConnection.Courses.Find(1));
                dbConnection.SaveChanges();

                // Get and list all students.
                var result = dbConnection.Students
                             .Select(st => new { Student = st, Courses = st.Courses });

                foreach (var item in result)
                {
                    Console.WriteLine(item.Student.ID);
                    Console.WriteLine(item.Student.FirstName + " " + item.Student.LastName);
                    Console.WriteLine(item.Student.Number);
                    Console.WriteLine("\t{0}", string.Join(", ", item.Courses.Select(c => c.Name)));
                }
            }
        }
        internal static void InitialHomeworkSubmissionSeed(StudentSystemContext context)
        {
            Random random = new Random();

            var contents = new string[]
            {
                "Management functions",
                "Group conflicts",
                "Sustanable development",
                "Brain storming",
                "Мanagement structures"
            };

            for (int i = 0; i < contents.Length; i++)
            {
                context.HomeworkSubmissions.Add(new Homework()
                {
                    Content        = contents[i],
                    ContentType    = Enum.Parse <ContentType>(random.Next(1, 3).ToString()),
                    SubmissionTime = DateTime.Now.AddDays(7),
                    StudentId      = random.Next(1, 5),
                    CourseId       = random.Next(1, 5)
                });

                context.SaveChanges();
            }
        }
Пример #13
0
        private static void SeedStudent(StudentSystemContext context)
        {
            Console.WriteLine("Register student:");
            Console.WriteLine("Enter your full name:");
            string studentName = Console.ReadLine();

            Console.WriteLine("Enter your phone number:");
            string phoneNumber = Console.ReadLine();

            Console.WriteLine("Enter your birthday:");
            Console.WriteLine("If you do not want to issue this personal information, press 'n'");
            string   birthdayInString = Console.ReadLine();
            DateTime birthday         = default(DateTime);

            if (birthdayInString != "n")
            {
                birthday = Convert.ToDateTime(birthdayInString);
            }

            var student = new Student()
            {
                Name        = studentName,
                PhoneNumber = phoneNumber,
                Birthday    = birthday
            };

            context.Students.Add(student);

            context.SaveChanges();
        }
Пример #14
0
        public void ImportStudents(int numberOfStudents)
        {
            Console.Write("Importing Students");
            var db = new StudentSystemContext();

            for (int i = 0; i < numberOfStudents; i++)
            {
                var student = new Student()
                {
                    Name   = RandomGenerator.GetString(2, 50),
                    Number = RandomGenerator.GetInt(7000000, 8000000)
                };

                db.Students.Add(student);

                if (i % 50 == 0)
                {
                    Console.Write(".");
                    db.SaveChanges();
                    db.Dispose();
                    db = new StudentSystemContext();
                }
            }

            db.SaveChanges();
            Console.WriteLine(" Completed!");
        }
Пример #15
0
        public void ImportCourses(int numberOfCourses)
        {
            var db = new StudentSystemContext();

            Console.Write("Importing Courses");

            for (int i = 0; i < numberOfCourses; i++)
            {
                var course = new Course()
                {
                    Name        = RandomGenerator.GetString(10, 100),
                    Description = RandomGenerator.GetString(100, 1000)
                };

                db.Courses.Add(course);

                if (i % 50 == 0)
                {
                    Console.Write(".");
                    db.SaveChanges();
                    db.Dispose();
                    db = new StudentSystemContext();
                }
            }

            db.SaveChanges();
            Console.WriteLine(" Completed!");
        }
Пример #16
0
        static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <StudentSystemContext, Configuration>());
            var db = new StudentSystemContext();

            using (db)
            {
                var homework = new Homework();
                var student  = new Student();
                var course   = new Course();

                student.FirstName     = "Gancho";
                student.LastName      = "Minchev";
                student.StudentNumber = 12345;

                course.Name = "Animals";
                course.Students.Add(student);
                course.Homeworks.Add(homework);
                course.Materials = "Books";
                course.Students.Add(student);

                homework.Content = "African Animals";
                homework.Course  = course;
                student.Homeworks.Add(homework);


                db.SaveChanges();
            }
        }
        static void Main()
        {
            Database.SetInitializer
                (new MigrateDatabaseToLatestVersion <StudentSystemContext, Configuration>());
            StudentSystemContext studentSystemContext = new StudentSystemContext();
            var studentHomework = new Homework()
            {
                Content = "Student Homework"
            };
            var student = new Student()
            {
                Name = "Ivancho", Number = 666666
            };

            student.Homeworks.Add(studentHomework);
            var courseHomework = new Homework()
            {
                Content = "Course Homework"
            };
            var course = new Course()
            {
                Name = "Databases", Description = "Very useful course"
            };

            course.Homeworks.Add(courseHomework);
            course.Students.Add(student);
            student.Courses.Add(course);

            studentSystemContext.Students.Add(student);
            studentSystemContext.Courses.Add(course);
            studentSystemContext.Homeworks.Add(studentHomework);
            studentSystemContext.Homeworks.Add(courseHomework);
            studentSystemContext.SaveChanges();
        }
Пример #18
0
        private void SeedResouces(StudentSystemContext context)
        {
            if (context.Resources.Any())
            {
                return;
            }

            var basketResource = new Resource
            {
                Name         = "Basketball for begginers",
                ResourceType = ResourceType.Document,
                URL          = "www.learntoplayball.com"
            };

            var bridgeResource = new Resource
            {
                Name         = "Bridge for begginers",
                ResourceType = ResourceType.Video,
                URL          = "www.bridgebaron.com"
            };

            var partyResource = new Resource
            {
                Name         = "PartyHard!!!",
                ResourceType = ResourceType.Video,
                URL          = "www.HernanCattaneo.com"
            };

            context.Resources.AddOrUpdate(basketResource);
            context.Resources.AddOrUpdate(bridgeResource);
            context.Resources.AddOrUpdate(partyResource);

            context.SaveChanges();
        }
Пример #19
0
        static void Main(string[] args)
        {
            var ctx = new StudentSystemContext();//app is launched and DB is created. That is the first approach.

            //ctx is short for context
            //the second approach is ctx.Database.CreateIfNotExist();
            //the DB is created according to the ctx
            //db.Students.Add();
            try
            {
                ctx.Students.Add(new Student()
                {
                    FirstName = "Ivan",
                    LastName  = "Atanasov",
                });

                ctx.SaveChanges();
            }
            catch (DbEntityValidationException ex)//lookup how to see the inner exception
            {
                throw;
            }

            Console.WriteLine(ctx.Students.Count());
        }
Пример #20
0
        static void Main()
        {
            /* Well, the model works, adding a course, student and a homework is ok - relations seem right.
             * We've got seeding as well.
             * Sorry, that the console application is so poor on functionality, but a lot of homeworks need to be done
             * For the sake of the demo, I hope this will be enough
             * Thanks!
             * */

            Database.SetInitializer(new MigrateDatabaseToLatestVersion <StudentSystemContext, Configuration>());
            StudentSystemContext ctx = new StudentSystemContext();

            using (ctx)
            {
                var course = new Course {
                    Name = "Javascript", Description = "JS Course Description"
                };
                ctx.Courses.Add(course);

                var student = new Student {
                    Name = "Pesho Peshov", Number = "1"
                };
                ctx.Students.Add(student);
                course.Students.Add(student);

                var homework = new Homework {
                    Content = "JS Homework", Course = course, Student = student
                };
                ctx.Homeworks.Add(homework);

                ctx.SaveChanges();

                Console.WriteLine("Ready.");
            }
        }
        static void Main()
        {
            Database.SetInitializer(new System.Data.Entity.MigrateDatabaseToLatestVersion
                                    <StudentSystemContext, Configuration>());

            var db = new StudentSystemContext();

            var student = new Student {
                Name = "Pesho", Number = 123456
            };

            db.Students.Add(student);

            var course = new Course();

            course.Name        = "PHP";
            course.Description = "Course for PHP Dummies";
            course.Materials   = "Xampp, Browser";
            course.Students.Add(student);
            student.Courses.Add(course);
            db.Courses.Add(course);

            var homework = new Homework();

            homework.Content  = "PHP Homework";
            homework.TimeSent = DateTime.Now;
            homework.Course   = course;
            homework.Student  = student;

            db.Homeworks.Add(homework);

            db.SaveChanges();
        }
Пример #22
0
        public static void Main()
        {
            using var db = new StudentSystemContext();

            db.Database.Migrate();

            db.SaveChanges();
        }
Пример #23
0
        static void Main()
        {
            var ctx = new StudentSystemContext();

            var students = ctx.Students.ToList();

            ctx.SaveChanges();
        }
Пример #24
0
 internal static void InitialStudentCoursesSeed(StudentSystemContext db, int count)
 {
     for (int i = 0; i < count; i++)
     {
         db.StudentCourses.Add(NewStudentCourse());
         db.SaveChanges();
     }
 }
 public static void InitialStudentSeed(StudentSystemContext db, int count)
 {
     for (int i = 0; i < count; i++)
     {
         db.Students.Add(NewStudent());
         db.SaveChanges();
     }
 }
Пример #26
0
 private static int SeedStudents(List <Student> students)
 {
     using (var context = new StudentSystemContext())
     {
         context.Students.AddRange(students);
         return(context.SaveChanges());
     }
 }
Пример #27
0
 private static int SeedCourses(List <Course> courses)
 {
     using (var context = new StudentSystemContext())
     {
         context.Courses.AddRange(courses);
         return(context.SaveChanges());
     }
 }
Пример #28
0
        static void Main(string[] args)
        {
            var db = new StudentSystemContext();

            db.Database.EnsureDeleted();
            db.Database.EnsureCreated();

            db.SaveChanges();
        }
Пример #29
0
        private static int SeedTable <TEntity>(List <TEntity> entities) where TEntity : class
        {
            using (var context = new StudentSystemContext())
            {
                context.Set <TEntity>().AddRange(entities);

                return(context.SaveChanges());
            }
        }
Пример #30
0
        public static void Main(string[] args)
        {
            using (var db = new StudentSystemContext())
            {
                db.Database.Migrate();

                db.SaveChanges();
            }
        }
Пример #31
0
    static void Main()
    {
        Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>());

        StudentSystemContext studentSystemDb = new StudentSystemContext();

        foreach (var item in studentSystemDb.Students)
        {
            Console.WriteLine("Name: {0} with studentNumber {1}",item.StudentName +' '+ item.StudentLastName,item.StudentNumber);
        }

        studentSystemDb.SaveChanges();
    }
Пример #32
0
        public static void Main(string[] args)
        {
            var context = new StudentSystemContext();

            var material = new Material
            {
                Content = "Material"
            };
            var course = new Course
            {
                Description = "We learn databases",
                Name = "DB"
            };

            course.Materials.Add(material);

            var homework = new Homework
            {
                Content = "Task",
                Course = course,
                Datesent = DateTime.Now
            };

            var student = new Student
            {
                Name = "Pesho",
                StudentNumber = "12345"
            };

            student.Courses.Add(course);
            student.Homeworks.Add(homework);

            context.Students.Add(student);

            context.SaveChanges();
        }