Advertisement
klokotnitza

Untitled

Dec 19th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. public class CommentsController : ApiController
  2. {
  3. private ICommentService commentsService;
  4.  
  5. public CommentsController(ICommentService commentsService)
  6. {
  7. this.commentsService = commentsService;
  8. }
  9.  
  10. public IQueryable<Comment> Get()
  11. {
  12. return commentsService.GetAll();
  13. }
  14.  
  15. public HttpResponseMessage Get(int id)
  16. {
  17. var comment = commentsService.GetComment(id);
  18.  
  19. if (comment == null)
  20. {
  21. return this.Request.CreateErrorResponse(HttpStatusCode.NotFound, "Comment not found!");
  22. }
  23.  
  24. return this.Request.CreateResponse(HttpStatusCode.OK, comment);
  25. }
  26.  
  27. public HttpResponseMessage Post([FromBody]Comment comment)
  28. {
  29. commentsService.Add(comment);
  30.  
  31. var message = this.Request.CreateResponse(HttpStatusCode.Created);
  32. message.Headers.Location = new Uri(this.Request.RequestUri + comment.CommentID.ToString(CultureInfo.InvariantCulture));
  33.  
  34. return message;
  35. }
  36.  
  37. public void Put([FromBody]Comment comment)
  38. {
  39. commentsService.Modify(comment);
  40. }
  41.  
  42. public void Delete([FromBody]Comment comment)
  43. {
  44. commentsService.Remove(comment);
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement