public ActionResult Create([Bind(Include = "StudentID,StudentName,StudentAlias,Password,Team,Motto,TeacherID,GroupNum")] StudentInfo studentInfo) { if (ModelState.IsValid) { db.StudentInfo.Add(studentInfo); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TeacherID = new SelectList(db.TeacherInfo, "TeacherID", "TeacherName", studentInfo.TeacherID); return(View(studentInfo)); }
public void Save() { using (StudentInfoManagementEntities se = new StudentInfoManagementEntities()) { var Student01 = new StudentInfo() { StudentID = this.Account, Password = this.Password }; se.StudentInfo.Add(Student01); se.SaveChanges(); } }
public ActionResult Delete(string id) { try { StudentInfoManagementEntities se = new StudentInfoManagementEntities(); var Student01 = se.StudentInfo.FirstOrDefault(m => m.StudentID == id); if (Student01 != null) { se.StudentInfo.Remove(Student01); se.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } return(View()); }
public ActionResult Edit(string id, FormCollection collection) { try { if (ModelState.IsValid) { StudentInfoManagementEntities se = new StudentInfoManagementEntities(); var model = se.StudentInfo.FirstOrDefault(m => m.StudentID == id); string[] strArr = collection.AllKeys; TryUpdateModel(model, strArr); se.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } return(View()); }