public async Task <IHttpActionResult> PostTrainPost(TrainPost trainPost) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.TrainPost.Add(trainPost); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (TrainPostExists(trainPost.PostID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = trainPost.PostID }, trainPost)); }
public async Task <IHttpActionResult> PutTrainPost(int id, TrainPost trainPost) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != trainPost.PostID) { return(BadRequest()); } db.Entry(trainPost).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TrainPostExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetTrainPost(int id) { TrainPost trainPost = await db.TrainPost.FindAsync(id); if (trainPost == null) { return(NotFound()); } return(Ok(trainPost)); }
public async Task <IHttpActionResult> DeleteTrainPost(int id) { TrainPost trainPost = await db.TrainPost.FindAsync(id); if (trainPost == null) { return(NotFound()); } db.TrainPost.Remove(trainPost); await db.SaveChangesAsync(); return(Ok(trainPost)); }