public JsonResult SaveMessage(SaveMessageViewModel viewModel) { if (ModelState.IsValid) { try { using (var transaction = UnitOfWork.Begin()) { _processor.Process <CreateArticleMessageCommand>(new CreateArticleMessageCommand( viewModel.ArticleId, CurrentUser.UserId, viewModel.Comment)); transaction.Commit(); return(new JsonResultObjec <string>(true, "评论成功")); } } catch (Exception ex) { // 记录日志 LogServer.Error("保存已登录用户评论失败", ex.Message, HttpContext.Request.Path); if ((ex is PowerException) || (ex is BusinessException)) { return(new JsonResultObjec <string>(false, ex.Message)); } else { return(new JsonResultObjec <string>(false, "评论失败,请联系管理员!")); } } } return(new JsonResultObjec <string>(false, "评论失败,请正确填写评论内容!")); }
public ActionResult AnonymousUserReply(int id) { var viewModel = new SaveMessageViewModel() { ArticleId = id }; return(View("_AnonymousUserReply", viewModel)); }
public PartialViewResult UserReply(int id) { var viewModel = new SaveMessageViewModel() { ArticleId = id }; return(PartialView("_UserReply", viewModel)); }
public ActionResult SaveAnonymousUserMessage(SaveMessageViewModel viewModel) { if (ModelState.IsValid) { try { using (var transaction = UnitOfWork.Begin()) { _processor.Process <CreateArticleMessageCommand>(new CreateArticleMessageCommand( viewModel.ArticleId, viewModel.NickName, viewModel.Comment) { WebSiteUrl = viewModel.WebSiteUrl }); transaction.Commit(); } return(new JsonResultObjec <string>(true, "评论成功")); } catch (Exception ex) { // 记录日志 LogServer.Error("保存未登录用户评论失败", ex.Message, HttpContext.Request.Path); if ((ex is PowerException) || (ex is BusinessException)) { return(new JsonResultObjec <string>(false, ex.Message)); } else { return(new JsonResultObjec <string>(false, "评论失败,请联系管理员!")); } } } var errorStr = new StringBuilder(); foreach (var item in ModelState) { foreach (var value in item.Value.Errors) { errorStr.AppendLine(value.ErrorMessage); } } return(new JsonResultObjec <string>(false, string.Format("{0}", errorStr))); }