// 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)); } }
// 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); } }