Example #1
0
        /// <summary>
        /// A partial view displaying the comment form
        /// Users can use this form to enter comments
        /// </summary>
        /// <returns>
        /// The System.Web.Mvc.ActionResult.
        /// </returns>
        public ActionResult CommentFormControl(string id)
        {
            CommenterProfile comProfile = ProfileComp.GetCommenterProfile();
            InsertCommentModel model = new InsertCommentModel() { FileID = id, Name = comProfile.Name, Url = comProfile.Url };
            if (this.User.Identity.IsAuthenticated)
            {
                model.IsAuthor = true;
            }

            this.ViewData.Model = model;
            return this.PartialView();
        }
Example #2
0
        public ActionResult Create(InsertCommentModel model)
        {
            string message = string.Empty;
            bool result = false;
            try
            {
                if (!string.IsNullOrEmpty(model.Url) && this.ModelState.IsValidField("Url"))
                {
                    // Check if URL is valid
                    if (!MvcLiteBlog.Helpers.UrlHelper.IsValidUrl(model.Url))
                    {
                        this.ModelState.AddModelError("Url", "请输入正确的Url地址");
                    }
                }

                if (this.ModelState.IsValid)
                {
                    CommentComp.Insert(model.FileID, model.Name, model.Url ?? string.Empty, model.CommentText, model.IsAuthor);
                    message = "评论已提交";
                    if (SettingsComp.GetSettings().CommentModeration)
                    {
                        message = "评论已提交,并等待管理员审核";
                    }

                    ProfileComp.SetCommenterProfile(model.Name, model.Url ?? string.Empty);
                    result = true;
                }
                else
                {
                    message = string.Empty;
                    foreach (string key in this.ModelState.Keys)
                    {
                        foreach (ModelError err in this.ModelState[key].Errors)
                        {
                            if (err.ErrorMessage != string.Empty)
                            {
                                message += err.ErrorMessage + "<br />";
                            }
                        }
                    }

                    result = false;
                }
            }
            catch
            {
                message = "评论ID不能修改";
            }

            return this.Json(new { Message = message, Result = result, Id = model.FileID });
        }