Example #1
0
        public async Task <IActionResult> GetArticle(int id)
        {
            var article = await _repo.GetArticleAsync(id);

            var articleToReturn = _mapper.Map <ArticleToReturnDto>(article);


            return(Ok(articleToReturn));
        }
Example #2
0
        public async Task <IActionResult> AddComment(CommentToCreateDto commentToCreate)
        {
            var comment = _mapper.Map <Comment>(commentToCreate);

            comment.article = await _repo.GetArticleAsync(commentToCreate.ArticleId);

            comment.Commenter = await _repo.GetUserAsync(commentToCreate.CommenterId);

            _repo.Add(comment);

            if (await _repo.SaveAll())
            {
                return(Ok(comment));
            }

            throw new Exception("Comment failed to post");
        }