コード例 #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;
        }
コード例 #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);
 }
コード例 #3
0
ファイル: CommentRepository.cs プロジェクト: yagopv/TestAPI
        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;
        }
コード例 #4
0
ファイル: CommentRepository.cs プロジェクト: yagopv/TestAPI
 public void AddComment(Comment Comment)
 {
     Comments.Add(Comment);
 }