public IHttpActionResult PuttStudent(int id, tStudent tStudent) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tStudent.f學生編號) { return(BadRequest()); } db.Entry(tStudent).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tStudentExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create(tStudent student) { if (ModelState.IsValid) { db.tStudent.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Create(tStudent student) { if (ModelState.IsValid) //確認所有驗證器都通過後會傳回true { db.tStudent.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); //當驗證不通過時,將表單的值保留必須將model當參數丟給view }
public ActionResult Create(tStudent stu) { //true = Module的驗證器,完全通過 if (ModelState.IsValid) { db.tStudent.Add(stu); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(stu)); }
public IHttpActionResult GettStudent(int id) { tStudent tStudent = db.tStudents.Find(id); if (tStudent == null) { return(NotFound()); } return(Ok(tStudent)); }
public IHttpActionResult PosttStudent(tStudent tStudent) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.tStudents.Add(tStudent); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = tStudent.f學生編號 }, tStudent)); }
public IHttpActionResult DeletetStudent(int id) { tStudent tStudent = db.tStudents.Find(id); if (tStudent == null) { return(NotFound()); } db.tStudents.Remove(tStudent); db.SaveChanges(); return(Ok(tStudent)); }
public ActionResult Edit (string fStuId, string fName, string fEmail, int fScore, tStudent student) { if (ModelState.IsValid) { string sql = "Update tStudent " + "set fName=N'" + fName + "'," + "fEmail='" + fEmail + "'," + "fScore=" + fScore + "" + " where fStuId='" + fStuId + "'" ; excuteSql(sql); return(RedirectToAction("Index")); } return(View(student)); }