예제 #1
0
 // PUT api/<controller>/5
 public HttpResponseMessage PutComment(int CommentID, data.Comment comment)
 {
     if (ModelState.IsValid && CommentID == comment.CommentID)
     {
         comment = commentFactory.SaveComment(comment);
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
     else
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest));
     }
 }
예제 #2
0
        // POST api/<controller>
        public HttpResponseMessage PostComment(data.Comment comment)
        {
            if (ModelState.IsValid)
            {
                comment.CommentDate = DateTime.Now;
                comment             = commentFactory.SaveComment(comment);
                Comments commentView = new Comments();
                commentView.CommentID      = comment.CommentID.ToString();
                commentView.CommentContent = comment.CommentContent;
                commentView.CommentAuthor  = comment.CommentAuthor;
                commentView.PostID         = comment.PostID.ToString();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, commentView);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { CommentID = comment.CommentID }));
                return(response);
            }
            else
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
                //   return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }