public void AddNewStudent(Student student)
 {
     using (StudentDB2Context db = new StudentDB2Context())
     {
         db.Students.Add(student);
         db.SaveChanges();
     }
 }
Exemple #2
0
        public ActionResult Index(Student student)
        {
            if (student.StudentId > 0)
            {
                using (StudentDB2Context db = new StudentDB2Context())
                {
                    db.Entry(student).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
            else
            {
                using (StudentDB2Context db = new StudentDB2Context())
                {
                    db.Students.Add(student);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index", "Home"));
        }