public ActionResult <BlogPostViewModel> PostBlogPost(BlogPostViewModel blogPost)
        {
            if (blogPost == null)
            {
                logger.LogDebug("Received a null content");
                return(BadRequest());
            }

            var category = categoryService.Get(blogPost.CategoryId);

            if (category == null)
            {
                logger.LogDebug("Category {Id} not found", blogPost.CategoryId);
                return(BadRequest("Category not found"));
            }

            var post = new BlogPost()
            {
                Category = category,
                Creator  = blogPost.Creator,
                Title    = blogPost.Title,
                Body     = blogPost.Body,
                Dt       = blogPost.Dt
            };

            postService.Add(post);

            return(CreatedAtAction("GetBlogPost", new { id = post.PostId }, new BlogPostViewModel(post)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Details(int?Id)
        {
            if (Id == null)
            {
                return(NotFound());
            }
            var controller = nameof(BlogCategoriesController).Split("Controller")[0];
            var html       = "detail";

            var model = await _blogCategoryService.Get(Id);

            if (User.IsInRole(Roles.Owner) || User.Identity.IsAuthenticated)
            {
                html = "managedetail";
            }

            return(View($"~/Views/{controller}/{html}.cshtml", model));
        }