public void AddNewStudent(Student student) { using (StudentDB2Context db = new StudentDB2Context()) { db.Students.Add(student); db.SaveChanges(); } }
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")); }