public async Task<IHttpActionResult> PutStudent(int id, Student student) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != student.ID) { return BadRequest(); } db.Entry(student).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
/// <summary> /// Creates a new product with default values /// </summary> /// <returns></returns> internal Student Create() { Student student = new Student { EnrollmentDate = DateTime.Now }; return student; }
public async Task<IHttpActionResult> PostStudent(Student student) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Students.Add(student); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = student.ID }, student); }