Exemple #1
0
        public ActionResult ApproveComment(Guid postId, Guid commentId)
        {
            var post = _postsRepository.Find(postId);

            post.ApproveComment(commentId);

            _postsRepository.Save(post);

            return(RedirectToRoute("Admin.Comments"));
        }
Exemple #2
0
        public ActionResult AddCommentToPublishedPost(Guid postId, DisplayPublishedPostViewModel model)
        {
            if (ModelState.IsValid)
            {
                var postsRepository = new PostsRepository(MvcApplication.MongoDatabase);

                var post = postsRepository.Find(postId);

                post.AddComment(model.NewComment.Author, model.NewComment.Comment);

                postsRepository.Save(post);
            }

            return(RedirectToRoute("Posts.DisplayPublishedPost", new { postId }));
        }
        public ActionResult AddCommentToPublishedPost(Guid postId, DisplayPublishedPostViewModel model)
        {
            if (ModelState.IsValid)
            {
                var postsRepository = new PostsRepository(MvcApplication.MongoDatabase);

                var post = postsRepository.Find(postId);

                post.AddComment(model.NewComment.Author, model.NewComment.Comment);

                postsRepository.Save(post);
            }

            return RedirectToRoute("Posts.DisplayPublishedPost", new { postId });
        }
Exemple #4
0
        public IActionResult Search(string query)
        {
            var posts = _postsRepository.Find(query);

            return(View("Index", posts));
        }
Exemple #5
0
        public PostsModule()
        {
            var postsRepository   = new PostsRepository();
            var authorsRepository = new AuthorsRepository();
            var blogsRepository   = new BlogsRepository();

            Get["/Posts"] = p =>
            {
                var posts = postsRepository.GetAll();

                return(View["Posts/index", new { Posts = posts, Title = "Nancy Blog", Description = "A simple blog demo built with Nancy" }]);
            };

            Get["/Posts/{id}"] = p =>
            {
                var post = postsRepository.Find(p.id);

                return(View["Posts/show", new { Post = post, Title = "Nancy Blog", Description = "A simple blog demo built with Nancy" }]);
            };

            Get["/Posts/New"] = p =>
            {
                var post = new Post();

                var author = authorsRepository.Find(1);

                var blog = blogsRepository.Find(1);

                return(View["Posts/new", new { Post = post, Author = author, Blog = blog, Title = "Nancy Blog", Description = "A simple blog demo built with Nancy", Action = "Create" }]);
            };

            Post["/Posts/Create"] = p =>
            {
                Post post = this.Bind();

                var addedPost = postsRepository.Add(post);

                if (post.PostId != addedPost.PostId)
                {
                    return(Response.AsRedirect("/Posts"));
                }

                return(View[""]);
            };

            Get["/Posts/{id}/Edit"] = p =>
            {
                var post = postsRepository.Find(p.id);

                var author = authorsRepository.Find(1);

                var blog = blogsRepository.Find(1);

                return(View["Posts/edit", new { Post = post, Author = author, Blog = blog, Title = "Nancy Blog", Description = "A simple blog demo built with Nancy", Action = p.id + "/Update" }]);
            };

            Post["/Posts/Update"] = p =>
            {
                Post post = this.Bind();

                var modifiedPost = postsRepository.Update(post);

                if (true)
                {
                    return(Response.AsRedirect("/Posts"));
                }

                return(View[""]);
            };
        }