Пример #1
0
        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));
        }
Пример #2
0
 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
 }
Пример #4
0
 public ActionResult Create(tStudent stu)
 {
     //true = Module的驗證器,完全通過
     if (ModelState.IsValid)
     {
         db.tStudent.Add(stu);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(stu));
 }
Пример #5
0
        public IHttpActionResult GettStudent(int id)
        {
            tStudent tStudent = db.tStudents.Find(id);

            if (tStudent == null)
            {
                return(NotFound());
            }

            return(Ok(tStudent));
        }
Пример #6
0
        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));
        }
Пример #7
0
        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));
        }
Пример #8
0
 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));
 }