示例#1
0
        public async Task <ActionResult <BlogViewModel> > GetBlogViewModel(int?id, ClaimsPrincipal claimsPrincipal)
        {
            if (id is null)
            {
                return(new BadRequestResult());
            }
            var blogId = id.Value;
            var blog   = blogServices.GetBlog(blogId);

            if (blog is null)
            {
                return(new NotFoundResult());
            }
            if (!blog.Published)
            {
                var authorizationResult = await authorizationService.AuthorizeAsync(claimsPrincipal, blog, Operations.Read);

                if (!authorizationResult.Succeeded)
                {
                    return(DetermineActionResult(claimsPrincipal));
                }
            }
            return(new BlogViewModel {
                Blog = blog
            });
        }