public IActionResult Compose()
        {
            var post = new BlogPost();

            UserRepository.PrepareEntityForInsert(User, post);
            return(View(new PostViewModel()
            {
                IsEdit = false, Post = BlogPostViewModel.From(post)
            }));
        }
Exemple #2
0
        public IActionResult Update(UpdateBlogPostViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid model"));
            }

            var blog = _blogPostService.Update(vm.ToModel());

            return(Ok(BlogPostViewModel.From(blog)));
        }
Exemple #3
0
        public IActionResult Create(CreateBlogPostViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrors()));
            }

            var blog = _blogPostService.Create(vm.ToModel());

            return(Ok(BlogPostViewModel.From(blog)));
        }
Exemple #4
0
        public IActionResult Details(int id)
        {
            var result = _blogPostService.GetPost(id);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(BlogPostViewModel.From(result)));
        }
        public async Task <IActionResult> Index(string id)
        {
            var cancellationToken = CancellationToken.None;

            if (string.IsNullOrWhiteSpace(id))
            {
                return(NotFound());
            }
            var post = await BlogRepository.FindBySlugAsync(id, cancellationToken);

            if (post == null)
            {
                return(NotFound());
            }
            if (post.UtcPublishDate == null || post.UtcPublishDate > DateTime.UtcNow.Date)
            {
                return(NotFound());
            }
            var author = await BlogRepository.GetAuthorByUserIdAsync(post.CreatedByUserId, cancellationToken);

            if (author == null)
            {
                author = new BlogAuthor()
                {
                    DisplayName = "Unknown"
                }
            }
            ;
            var model = new PostViewModel()
            {
                Post     = BlogPostViewModel.From(post),
                PostDate = post.UtcPublishDate.Value.ToString("MMMM dd, yyyy"),
                Author   = author
            };

            return(View(new[] { model }));
        }
Exemple #6
0
        public IActionResult Recent()
        {
            var recents = _blogPostService.GetPosts().OrderByDescending(c => c.CreateDate).Take(5);

            return(Ok(recents.Select(bp => BlogPostViewModel.From(bp))));
        }