public async Task <IHttpActionResult> PostCommentsOntrain ([FromBody] CommentsOntrain commentsOntrain) { //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} db.CommentsOntrain.Add(commentsOntrain); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (CommentsOntrainExists(commentsOntrain.CommentID)) { return(Conflict()); } else { throw; } } //return CreatedAtRoute("DefaultApi", new { id = commentsOntrain.CommentID }, commentsOntrain); return(Ok(db.CommentsOntrain.ToListAsync())); }
public async Task <IHttpActionResult> PutCommentsOntrain(int id, CommentsOntrain commentsOntrain) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != commentsOntrain.CommentID) { return(BadRequest()); } db.Entry(commentsOntrain).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentsOntrainExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetCommentsOntrain(int id) { CommentsOntrain commentsOntrain = await db.CommentsOntrain.FindAsync(id); if (commentsOntrain == null) { return(NotFound()); } return(Ok(commentsOntrain)); }
public async Task <IHttpActionResult> getComment([FromUri] int commentID) { CommentsOntrain comment = await db.CommentsOntrain.FirstOrDefaultAsync(c => c.CommentID == commentID); if (comment == null) { return(NotFound()); } return(Ok(comment)); }
public async Task <IHttpActionResult> DeleteCommentsOntrain(int id) { CommentsOntrain commentsOntrain = await db.CommentsOntrain.FindAsync(id); if (commentsOntrain == null) { return(NotFound()); } db.CommentsOntrain.Remove(commentsOntrain); await db.SaveChangesAsync(); return(Ok(commentsOntrain)); }