コード例 #1
0
        public ActionResult Show(string idAndSlug)
        {
            var parts = SepreateIdAndSlug(idAndSlug);

            if (parts == null)
            {
                return(HttpNotFound());
            }

            using (db = new MainDBContext())
            {
                var post = db.Posts.Find(parts.Item1);
                if (post == null || post.IsDeleted)
                {
                    return(HttpNotFound());
                }

                if (!post.Slug.Equals(parts.Item2, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(RedirectToRoutePermanent("Post", new { id = parts.Item1, slug = post.Slug }));
                }


                var newPost = new PostsShow
                {
                    Post = post
                };
                newPost.Post.Tags = post.Tags.ToList();
                return(View(newPost));
            }
        }
コード例 #2
0
        public ActionResult Show(string id, string slug, PostsShow model)
        {
            Post selectedPost = DatabaseManager.Session.Load <Post>(model.PostId);

            Comment comment = new Comment
            {
                Content     = model.CommentContent,
                DateCreated = DateTime.UtcNow,
                User        = UserCache.CurrentUser,
            };

            // Save new comment
            //DatabaseManager.Session.Save(comment);

            selectedPost.Comments.Add(comment);

            // Update post
            DatabaseManager.Session.SaveOrUpdate(selectedPost);

            return(RedirectToAction("show"));
        }
コード例 #3
0
        public ActionResult Show(string id, string slug, PostsShow model)
        {
            Post selectedPost = DatabaseManager.Session.Load<Post>(model.PostId);

            Comment comment = new Comment
            {
                Content = model.CommentContent,
                DateCreated = DateTime.UtcNow,
                User = UserCache.CurrentUser,
            };

            // Save new comment
            //DatabaseManager.Session.Save(comment);

            selectedPost.Comments.Add(comment);

            // Update post
            DatabaseManager.Session.SaveOrUpdate(selectedPost);

            return RedirectToAction("show");
        }