public IHttpActionResult EditStudent(Sinh_Vien student) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } using (var ctx = new DemoEntities()) { var existingStudent = ctx.Sinh_Vien.Where(s => s.MSV == student.MSV) .FirstOrDefault <Sinh_Vien>(); if (existingStudent != null) { existingStudent.Ho = student.Ho; existingStudent.Ten = student.Ten; ctx.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
//Get action methods of the previous section public IHttpActionResult InsertNewStudent([FromBody] Sinh_Vien student) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } using (var ctx = new DemoEntities()) { try { ctx.Sinh_Vien.Add(student); ctx.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } } return(Ok()); }