public ActionResult Create([Bind(Include = "StudentID,ClassID,FullName,Gender,Birthday,Address,Email,PhoneNumber")] Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ClassID = new SelectList(db.Classes, "ClassID", "Period", student.ClassID); return(View(student)); }
public HttpResponseMessage EditStudent(string id, [FromBody] Student student) { try { using (ECLASSEntities db = new ECLASSEntities()) { var s = db.Students.SingleOrDefault(x => x.StudentID == id); if (s != null) { s.FullName = student.FullName; s.ClassID = student.ClassID; s.Birthday = student.Birthday; s.Address = student.Address; s.Email = student.Email; s.Gender = student.Gender; db.SaveChanges(); } return(Request.CreateResponse(HttpStatusCode.OK, s)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public HttpResponseMessage AddStudent([FromBody] Student student) { try { using (ECLASSEntities db = new ECLASSEntities()) { db.Students.Add(student); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public HttpResponseMessage DeleteStudent(string id) { try { using (ECLASSEntities db = new ECLASSEntities()) { Student s = db.Students.SingleOrDefault(x => x.StudentID == id); db.Students.Remove(s); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, s)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }