示例#1
0
        public ActionResult Add(CommentViewModel viewModel)
        {
            var commentStatus = false;

            if (ModelState.IsValid)
            {
                viewModel.Comment.PostID = viewModel.Post.ID;
                if (Request.IsAuthenticated)
                {
                    viewModel.Comment.UserID = this.GetUserId();
                }

                this.commentService.AddComment(viewModel.Comment);
                commentStatus = true;
            }

            return this.RedirectToPostPage(viewModel, commentStatus);
        }
示例#2
0
        /// <summary>
        /// The redirect to post page.
        /// </summary>
        /// <param name="viewModel">
        /// The view model.
        /// </param>
        /// <param name="commentingStatus">
        /// The commenting status.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        private ActionResult RedirectToPostPage(CommentViewModel viewModel, bool commentingStatus)
        {
            var commentStatus = commentingStatus ? "comment-successed" : "comment-errored";
            if (viewModel.Post.EntryType == 1)
            {
                return this.RedirectToRoute(
                    "Post",
                    new
                        {
                            year = viewModel.Post.CreateTime.Year,
                            month = viewModel.Post.CreateTime.Month.ToString("00"),
                            url = viewModel.Post.Url,
                            status = commentStatus
                        });
            }

            return this.RedirectToRoute("Default", new { url = viewModel.Post.Url, status = commentStatus });
        }