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)); }
// GET: Student/Edit/5 public ActionResult Edit(int id) { var db = new AdvWebDevProjectEntities(); vStudent theStudent = db.vStudents.Find(id); if (theStudent == null) { return(HttpNotFound()); } return(View(theStudent)); }
public ActionResult Create(vStudent theStudent) { using (var db = new AdvWebDevProjectEntities()) { try { if (ModelState.IsValid) { db.vStudents.Add(theStudent); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError("", $"An error occurred: {ex.Message}"); } } return(View(theStudent)); }
public ActionResult Edit(vStudent theStudent) { using (var db = new AdvWebDevProjectEntities()) { if (ModelState.IsValid) //verifies that the data submitted in the form can be used to modify (edit or update) { if (TryUpdateModel(theStudent)) { try { db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", $"An error occurred: {ex.Message}"); } } } } return(View(theStudent)); }
// GET: Student public ActionResult Index() { var db = new AdvWebDevProjectEntities(); return(View(db.vStudents.ToList())); }