public ActionResult Create([Bind(Include = "ClassId,ClassName,ClassDate,ClassDescription")] Class @class) { if (ModelState.IsValid) { db.Classes.Add(@class); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(@class)); }
public ActionResult Create([Bind(Include = "StudentId,StudentName,StudentEmail,StudentLogin,StudentPassword")] Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
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 Create(vClass theClass) { try { if (ModelState.IsValid) { db.vClasses.Add(theClass); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(theClass)); }
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)); }