Esempio n. 1
0
        public static void AddMarks(MarksContext db)
        {
            if (!db.Marks.Any())
            {
                Student        st    = db.Students.ToList().Find(x => x.Name.Contains("Шопинський"));
                Student        st2   = db.Students.ToList().Find(x => x.Name.Contains("Майборода Володимир"));
                Student        st3   = db.Students.ToList().Find(x => x.Name.Contains("Надточій Євген"));
                Semester       sem   = db.Semesters.First();
                List <Subject> subj  = db.Subjects.ToList();
                List <Mark>    marks = new List <Mark>();

                marks.Add(new Mark
                {
                    Value    = 96,
                    Student  = st,
                    Semester = sem,
                    Subject  = subj[0]
                });

                marks.Add(new Mark
                {
                    Value    = 96,
                    Student  = st,
                    Semester = sem,
                    Subject  = subj[1]
                });

                marks.Add(new Mark
                {
                    Value    = 96,
                    Student  = st,
                    Semester = sem,
                    Subject  = subj[2]
                });

                marks.Add(new Mark
                {
                    Value    = 98,
                    Student  = st,
                    Semester = sem,
                    Subject  = subj[3]
                });

                marks.Add(new Mark
                {
                    Value    = 96,
                    Student  = st,
                    Semester = sem,
                    Subject  = subj[4]
                });

                marks.Add(new Mark
                {
                    Value    = 98,
                    Student  = st,
                    Semester = sem,
                    Subject  = subj[5]
                });

                marks.Add(new Mark
                {
                    Value    = 100,
                    Student  = st,
                    Semester = sem,
                    Subject  = subj[6]
                });

                //

                marks.Add(new Mark
                {
                    Value    = 88,
                    Student  = st2,
                    Semester = sem,
                    Subject  = subj[0]
                });

                marks.Add(new Mark
                {
                    Value    = 92,
                    Student  = st2,
                    Semester = sem,
                    Subject  = subj[1]
                });

                marks.Add(new Mark
                {
                    Value    = 90,
                    Student  = st2,
                    Semester = sem,
                    Subject  = subj[2]
                });

                marks.Add(new Mark
                {
                    Value    = 90,
                    Student  = st2,
                    Semester = sem,
                    Subject  = subj[3]
                });

                marks.Add(new Mark
                {
                    Value    = 75,
                    Student  = st2,
                    Semester = sem,
                    Subject  = subj[4]
                });

                marks.Add(new Mark
                {
                    Value    = 95,
                    Student  = st2,
                    Semester = sem,
                    Subject  = subj[5]
                });

                marks.Add(new Mark
                {
                    Value    = 96,
                    Student  = st2,
                    Semester = sem,
                    Subject  = subj[6]
                });

                //

                marks.Add(new Mark
                {
                    Value    = 72,
                    Student  = st3,
                    Semester = sem,
                    Subject  = subj[0]
                });

                marks.Add(new Mark
                {
                    Value    = 90,
                    Student  = st3,
                    Semester = sem,
                    Subject  = subj[1]
                });


                marks.Add(new Mark
                {
                    Value    = 92,
                    Student  = st3,
                    Semester = sem,
                    Subject  = subj[3]
                });

                marks.Add(new Mark
                {
                    Value    = 65,
                    Student  = st3,
                    Semester = sem,
                    Subject  = subj[4]
                });

                marks.Add(new Mark
                {
                    Value    = 84,
                    Student  = st3,
                    Semester = sem,
                    Subject  = subj[5]
                });

                marks.Add(new Mark
                {
                    Value    = 88,
                    Student  = st3,
                    Semester = sem,
                    Subject  = subj[6]
                });



                db.Marks.AddRange(marks);
                db.SaveChanges();
            }
        }
Esempio n. 2
0
        public static void FillDbFromPDF(MarksContext context)
        {
            if (!context.Students.Any())
            {
                Semester sem1 = new Semester
                {
                    Season = "Осінь",
                    Year   = 2016
                };
                Semester sem2 = new Semester
                {
                    Season = "Весна",
                    Year   = 2017
                };

                context.Semesters.AddRange(sem1, sem2);
                context.SaveChanges();

                string[] dirs     = Directory.GetDirectories("wwwroot\\pdf");
                var      students = new List <Student>();
                var      groups   = new List <Group>();
                var      ratings  = new List <Rating>();

                for (int k = 0; k < dirs.Length; k++)
                {
                    string[] paths = Directory.GetFiles(dirs[k]);

                    for (int i = 0; i < paths.Length; i++)
                    {
                        PDFParser parser = new PDFParser(paths[i]);

                        List <Group>       listg = parser.Groups;
                        List <StudentData> list  = parser.Students;

                        context.Groups.AddRange(listg);
                        context.SaveChanges();

                        for (int j = 0; j < list.Count; j++)
                        {
                            Student s = new Student
                            {
                                Name        = list[j].Name,
                                Group       = context.Groups.First(p => p.Name == list[j].Group),
                                IsBudgetary = list[j].Info == "контракт" ? false : true
                            };

                            students.Add(s);

                            Rating r = new Rating
                            {
                                Student  = s,
                                Semester = sem1,
                                Value    = list[j].Rating,
                                Bonus    = 0,
                                Note     = list[j].Info
                            };

                            ratings.Add(r);
                        }
                    }
                }

                context.Students.AddRange(students);
                context.Ratings.AddRange(ratings);
                context.SaveChanges();
            }
        }