Exemplo n.º 1
0
        public async Task <BlogPostResult> GetBlogPostById(string blogPostId)
        {
            var blogPost = await _blogPostRepository.GetBlogPostById(blogPostId);

            if (blogPost == null)
            {
                return new BlogPostResult
                       {
                           Data    = null,
                           Details = new ResultDetails
                           {
                               Message      = $"No blogPost with {blogPostId} was found.",
                               ResultStatus = ResultStatus.Failure
                           }
                       }
            }
            ;

            return(new BlogPostResult
            {
                Data = blogPost,
                Details = new ResultDetails {
                    ResultStatus = ResultStatus.Success
                }
            });
        }
Exemplo n.º 2
0
        public IActionResult GetBlogPostById(int id)
        {
            var blogPost = _blogPostRepository.GetBlogPostById(id);

            if (blogPost == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(blogPost));
            }
        }
Exemplo n.º 3
0
        public IActionResult GetById(int id)
        {
            try
            {
                var item = _repository.GetBlogPostById(id);
                if (item != null)
                {
                    var posts = Mapper.Map <BlogPostViewModel>(item);
                    return(Ok(posts));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to get get All Post: {ex}");
            }

            return(NotFound());
        }