public ActionResult Delete(vStudent theStudent) { using (var db = new AdvWebDevProjectEntities()) { if (ModelState.IsValid) { try { db.Entry(theStudent).State = System.Data.Entity.EntityState.Deleted; db.vStudents.Remove(theStudent); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", $"An error occurred: {ex.Message}"); } } else { ModelState.AddModelError("", "Model state was invalid."); } } return(View(theStudent)); }
public ActionResult Edit([Bind(Include = "ClassId,ClassName,ClassDate,ClassDescription")] Class @class) { if (ModelState.IsValid) { db.Entry(@class).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(@class)); }
public ActionResult Edit([Bind(Include = "StudentId,StudentName,StudentEmail,StudentLogin,StudentPassword")] Student student) { if (ModelState.IsValid) { db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }