public IHttpActionResult PostTrainNumbers(TrainNumbers trainNumbers) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.TrainNumbers.Add(trainNumbers); try { db.SaveChanges(); } catch (DbUpdateException) { if (TrainNumbersExists(trainNumbers.Id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = trainNumbers.Id }, trainNumbers); }
public IHttpActionResult PutTrainNumbers(int id, TrainNumbers trainNumbers) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != trainNumbers.Id) { return BadRequest(); } db.Entry(trainNumbers).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TrainNumbersExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }