/// <summary> /// 新增数据(评论) /// </summary> public AjaxResult InsertComment(TbArticleComment model, bool isApi = false) { if (model == null) { return(AjaxResult.Warning("参数错误")); } model.InsertTime = DateTime.Now; model.Type = 1; if (model.CommentID != 0) { model.Type = 2; } //修改浏览数 var article = Repository <TbArticle> .First(p => p.ID == model.ArticleID); article.CommentCount += 1; try { using (DbTrans trans = Db.Context.BeginTransaction()) { //添加信息 Repository <TbArticleComment> .Insert(trans, model, isApi); //修改浏览数 Repository <TbArticle> .Update(trans, article, p => p.ID == model.ArticleID, isApi); trans.Commit(); return(AjaxResult.Success()); } } catch (Exception) { return(AjaxResult.Error()); } }
public ActionResult SubmitFormForComment(TbArticleComment model) { try { model.InsertUserCode = base.UserCode; var data = _article.InsertComment(model); return(Content(data.ToJson())); } catch (Exception) { return(Error("")); } }
public HttpResponseMessage SubmitFormForComment([FromBody] TbArticleComment model) { var data = _article.InsertComment(model, true); return(data.ToJsonApi()); }