public IActionResult Insert(TeacherDetail model)
        {
            try
            {
                if (int.Parse(model.YearsOfExperience) < 0)
                {
                    ViewBag.Message = "You could not have had a negative years experience...";
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        db.TeacherDetails.Add(model);
                        db.SaveChanges();
                        ViewBag.SuccessMessage = "Yay! You are now listed as a teacher on HomeTeach";
                    }
                }
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                ViewBag.Message = "Oh No! Please input Values";
            }

            return(View(model));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <StudentDbContext, Configuration>());
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <TeacherDbContext, TeacherMigrations.Configuration>());

            using (var studentContext = new StudentDbContext())
            {
                Console.Write("please input student's name: ");
                var name    = Console.ReadLine();
                var student = new Student()
                {
                    StudentName = name
                };

                studentContext.Students.Add(student);
                studentContext.SaveChanges();
            }

            using (var teacherContext = new TeacherDbContext())
            {
                Console.Write("please input teacher's name: ");
                var name    = Console.ReadLine();
                var teacher = new Teacher()
                {
                    TeacherName = name
                };

                teacherContext.Teachers.Add(teacher);
                teacherContext.SaveChanges();
            }

            Console.ReadLine();
        }
Beispiel #3
0
 //add teacher
 public void AddTeacher(Teacher teacher)
 {
     teacherDb.DbSet.Add(teacher);
     teacherDb.SaveChanges();
 }