public IActionResult GetComments(int userId, int blogId, int postId, [FromQuery] CommentsResourceParameters commentsResourceParameters, [FromHeader(Name = nameof(HeaderNames.Accept))] string mediaType) { if (!_weblogDataRepository.UserExists(userId) || !_weblogDataRepository.BlogExists(blogId) || !_weblogDataRepository.PostExists(postId)) { return(NotFound()); } var commentEntities = _weblogDataRepository.GetComments(postId, commentsResourceParameters); var commentsToReturn = _mapper.Map <IEnumerable <CommentDto> >(commentEntities); Response.Headers.Add(PaginationHeader <Comment> .Get(commentEntities)); var includeLinks = MediaTypes.IncludeLinks(mediaType); if (!includeLinks) { return(Ok(commentsToReturn)); } var commentsWithLinks = commentsToReturn.Select(comment => { var links = CreateLinksForComment(userId, blogId, postId, comment.CommentId, comment.UserId); return(new CommentDtoWithLinks(comment, links)); }); var collectionToReturn = new { comments = commentsWithLinks, links = LinksForCollection.Create( CreateCommentsResourceUri, new int[] { userId, blogId, postId }, commentsResourceParameters, commentEntities.HasPrevious, commentEntities.HasNext) }; return(Ok(collectionToReturn)); }
public void PostExists() { //-- arrange var post = new Post { Title = "title", Body = "body", TimeCreated = DateTime.Now }; _repository.AddPost(1, post); _repository.Save(); //-- act var actual = _repository.PostExists(1); //-- assert Assert.IsTrue(actual); //-- clean up _repository.DeletePost(post); _repository.Save(); }