// POST /api/testapi public HttpResponseMessage Post(Comment Comment) { commentrepository.AddComment(Comment); var response = Request.CreateResponse<Comment>(HttpStatusCode.Created, Comment); string uri = Url.Link("DefaultApi", new { CommentId = Comment.CommentId }); response.Headers.Location = new Uri(uri); return response; }
// PUT /api/testapi/ public HttpResponseMessage Put(Comment comment) { var updated = commentrepository.UpdateComment(comment); if (!updated) { var response = new HttpResponseMessage(HttpStatusCode.NotFound); throw new HttpResponseException(response); } return new HttpResponseMessage(HttpStatusCode.NoContent); }
public bool UpdateComment(Comment Comment) { Comment repoComment = Comments.Where(p => p.CommentId == Comment.CommentId).FirstOrDefault(); if (repoComment == null) { return false; } repoComment.Title = Comment.Title; repoComment.Message = Comment.Message; return true; }
public void AddComment(Comment Comment) { Comments.Add(Comment); }