public async Task <HttpResponseMessage> Get(int id) { IStateFactory <comment, CommentSingleState> _stateFactory = new CommentSingleFactory(Request); var instance = CommentService.GetInstance(); var comment = await instance.GetCommentByIdAsync(id); if (comment.Success) { return(Request.CreateResponse(HttpStatusCode.OK, _stateFactory.Create(comment.Result), "application/json")); } return(Request.CreateResponse(HttpStatusCode.NotFound, new NotFound(Request.RequestUri, comment.Message), "application/problem+json")); }
public async Task <HttpResponseMessage> GetCommentsFromCommunity(int idCommunity) { IStateFactory <comment, CommentSingleState> _stateFactory = new CommentSingleFactory(Request); var instance = CommentService.GetInstance(); var comments = await instance.GetAllCommentsFromCommunity(idCommunity); if (comments.Success) { var res = comments.Result.Select <comment, CommentsCollectionState>(i => new CommentsCollectionFactory(Request).Create(i)); return(Request.CreateResponse(HttpStatusCode.OK, new { comments = res }, "application/json")); } return(Request.CreateResponse(HttpStatusCode.NotFound, new NotFound(Request.RequestUri, comments.Message), "application/problem+json")); }