コード例 #1
0
        public IActionResult PostTeachers(int id, string name)
        {
            var teacher = new Teachers()
            {
                te_id   = id,
                te_name = name
            };

            _context.Add(teacher);
            _context.SaveChanges();
            return(Ok("Created"));
        }
コード例 #2
0
        private static void AddTeacherCourses(TeachersContext db)
        {
            var random = new Random();

            var coursesIds = new List <string>
            {
                "038E641D-0F1E-4FB7-AD26-02008443E9F6",
                "B8F63F2F-4F35-437C-9F7F-3DB46752734D",
                "ADCA34E7-A43E-4248-B2F6-3FFC0D34A687",
                "B5F0105C-77DD-4273-8129-5642F2EE1E74",
                "D37DCBB3-AFC9-473A-BE58-70CC8D921426"
            };

            var teachers = db.Teachers.ToList();

            foreach (var courseId in coursesIds)
            {
                var teacherCourse1 = new TeacherCourse()
                {
                    Id        = Guid.NewGuid(), CourseId = Guid.Parse(courseId),
                    TeacherId = teachers.ElementAt(random.Next(0, 2)).Id
                };
                var teacherCourse2 = new TeacherCourse()
                {
                    Id        = Guid.NewGuid(),
                    CourseId  = Guid.Parse(courseId),
                    TeacherId = teachers.ElementAt(random.Next(2, 4)).Id
                };
                var teacherCourse3 = new TeacherCourse()
                {
                    Id        = Guid.NewGuid(),
                    CourseId  = Guid.Parse(courseId),
                    TeacherId = teachers.ElementAt(random.Next(4, 6)).Id
                };
                var teacherCourse4 = new TeacherCourse()
                {
                    Id        = Guid.NewGuid(),
                    CourseId  = Guid.Parse(courseId),
                    TeacherId = teachers.ElementAt(random.Next(6, teachers.Count)).Id
                };
                db.TeacherCourses.Add(teacherCourse1);
                db.TeacherCourses.Add(teacherCourse2);
                db.TeacherCourses.Add(teacherCourse3);
                db.TeacherCourses.Add(teacherCourse4);


                db.SaveChanges();
            }
        }
コード例 #3
0
 public void Create(Teacher teacher)
 {
     _context.Add(teacher);
     _context.SaveChanges();
 }
コード例 #4
0
        private static void AddTeachers(TeachersContext db)
        {
            db.Teachers.Add(new Teacher()
            {
                Name            = "Vlad Emil",
                CareerStartYear = 2005,
                Motto           = "Repetition Is the key of success.",
                YearOfBirth     = 1980
            });
            db.Teachers.Add(new Teacher()
            {
                Name            = "Goerge Racovita",
                CareerStartYear = 2010,
                Motto           = "Your limitation it’s only your imagination.",
                YearOfBirth     = 1986
            });
            db.Teachers.Add(new Teacher()
            {
                Name            = "Radu Cercel ",
                CareerStartYear = 2009,
                Motto           = "Push yourself, because no one else is going to do it for you.",
                YearOfBirth     = 1982
            });
            db.Teachers.Add(new Teacher()
            {
                Name            = "Petre Pavel",
                CareerStartYear = 2010,
                Motto           = "Sometimes later becomes never. Do it now.",
                YearOfBirth     = 1979
            });
            db.Teachers.Add(new Teacher()
            {
                Name            = "Grigore Dana",
                CareerStartYear = 2015,
                Motto           = " Great things never come from comfort zones.",
                YearOfBirth     = 1990
            });
            db.Teachers.Add(new Teacher()
            {
                Name            = "Eliza Radican",
                CareerStartYear = 2007,
                Motto           = "Dream it. Wish it. Do it.",
                YearOfBirth     = 1985
            });

            db.Teachers.Add(new Teacher()
            {
                Name            = "Mirela Cras",
                CareerStartYear = 2000,
                Motto           = "Work until your wishes come true",
                YearOfBirth     = 1985
            });

            db.Teachers.Add(new Teacher()
            {
                Name            = "Stefan Relu",
                CareerStartYear = 2009,
                Motto           = "Never stop trying.",
                YearOfBirth     = 1985
            });

            db.SaveChanges();
        }