Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CommentsController : ApiController
- {
- private ICommentService commentsService;
- public CommentsController(ICommentService commentsService)
- {
- this.commentsService = commentsService;
- }
- public IQueryable<Comment> Get()
- {
- return commentsService.GetAll();
- }
- public HttpResponseMessage Get(int id)
- {
- var comment = commentsService.GetComment(id);
- if (comment == null)
- {
- return this.Request.CreateErrorResponse(HttpStatusCode.NotFound, "Comment not found!");
- }
- return this.Request.CreateResponse(HttpStatusCode.OK, comment);
- }
- public HttpResponseMessage Post([FromBody]Comment comment)
- {
- commentsService.Add(comment);
- var message = this.Request.CreateResponse(HttpStatusCode.Created);
- message.Headers.Location = new Uri(this.Request.RequestUri + comment.CommentID.ToString(CultureInfo.InvariantCulture));
- return message;
- }
- public void Put([FromBody]Comment comment)
- {
- commentsService.Modify(comment);
- }
- public void Delete([FromBody]Comment comment)
- {
- commentsService.Remove(comment);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement