public async Task<IHttpActionResult> PostStudentRegistration(StudentRegistration studentRegistration) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.StudentRegistrations.Add(studentRegistration); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (StudentRegistrationExists(studentRegistration.Id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = studentRegistration.Id }, studentRegistration); }
public async Task<IHttpActionResult> PutStudentRegistration(int id, StudentRegistration studentRegistration) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != studentRegistration.Id) { return BadRequest(); } db.Entry(studentRegistration).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentRegistrationExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }