Beispiel #1
0
        // 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;
        }
Beispiel #2
0
 // 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);
 }
Beispiel #3
0
        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;
        }
Beispiel #4
0
 public void AddComment(Comment Comment)
 {
     Comments.Add(Comment);
 }