Exemplo n.º 1
0
        public async Task <IActionResult> Details([Bind("BlogPostID,AuthorName,CreatedTime,Content")] BlogPostCommentsViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                CommentModel comment = new CommentModel();

                comment.AuthorName  = viewModel.AuthorName;
                comment.CreatedTime = viewModel.CreatedTime;
                comment.Content     = viewModel.Content;

                BlogPostModel blogPost = await _context.BlogPostModel
                                         .SingleOrDefaultAsync(m => m.ID == viewModel.BlogPostID);

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

                comment.BlogPost = blogPost;
                _context.CommentModel.Add(comment);
                await _context.SaveChangesAsync();

                viewModel = await GetBlogPostCommentsViewModelFromBlogPost(blogPost);
            }
            return(View(viewModel));
        }
Exemplo n.º 2
0
        public ActionResult Delete(int[] ids)
        {
            if (ids == null || !ids.Any())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var model = new BlogPostCommentsViewModel();

            model.BlogPostComments = new List <BlogPostCommentViewModel>();

            foreach (int id in ids)
            {
                BlogPostComment comment = blogPostCommentService.Find(id);
                if (comment == null)
                {
                    continue;
                }

                model.BlogPostComments.Add(new BlogPostCommentViewModel
                {
                    Id   = comment.Id,
                    Name = comment.Name,
                });
            }
            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult ForApproval()
        {
            var comment = blogPostCommentService.FindAll().Where(c => c.IsApproved == false).ToList();
            var model   = new BlogPostCommentsViewModel
            {
                BlogPostComments = Mapper.Map <List <BlogPostCommentViewModel> >(comment)
            };

            return(View(model));
        }
Exemplo n.º 4
0
        private async Task <BlogPostCommentsViewModel> GetBlogPostCommentsViewModelFromBlogPost(BlogPostModel blogPost)
        {
            BlogPostCommentsViewModel viewModel = new BlogPostCommentsViewModel();

            viewModel.BlogPost = blogPost;

            List <CommentModel> comments = await _context.CommentModel
                                           .Where(x => x.BlogPost == blogPost).ToListAsync();

            viewModel.Comments = comments;

            return(viewModel);
        }
Exemplo n.º 5
0
        // GET: BlogPosts/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            BlogPostModel blogPostModel = await _context.BlogPostModel
                                          .SingleOrDefaultAsync(m => m.ID == id);

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

            BlogPostCommentsViewModel viewModel = await GetBlogPostCommentsViewModelFromBlogPost(blogPostModel);

            return(View(viewModel));
        }
        public ActionResult Delete(int[] ids)
        {
            if (ids == null || !ids.Any())
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var model = new BlogPostCommentsViewModel();
            model.BlogPostComments = new List<BlogPostCommentViewModel>();

            foreach (int id in ids)
            {
                BlogPostComment comment = blogPostCommentService.Find(id);
                if (comment == null) continue;

                model.BlogPostComments.Add(new BlogPostCommentViewModel
                {
                    Id = comment.Id,
                    Name = comment.Name,
                });
            }
            return View(model);
        }
 public ActionResult Index()
 {
     var comment = blogPostCommentService.FindAll().Where(c => c.IsApproved).ToList();
     var model = new BlogPostCommentsViewModel
     {
         BlogPostComments = Mapper.Map<List<BlogPostCommentViewModel>>(comment)
     };
     return View(model);
 }