/// <summary> /// 删除 /// </summary> /// <param name="commentId"></param> /// <returns></returns> public int Delete(CommentInfo comment) { string cmdText = string.Format("delete from [{0}comments] where [commentId] = @commentId", ConfigHelper.Tableprefix); using (var conn = new DapperHelper().OpenConnection()) { return conn.Execute(cmdText, new { commentId = comment.CommentId }); } }
public ActionResult Add(CommentInfo comment) { return Content("success"); }
/// <summary> /// 更新 /// </summary> /// <param name="comment"></param> /// <returns></returns> public int Update(CommentInfo comment) { string cmdText = string.Format(@"update [{0}comments] set PostId=@PostId, ParentId=@ParentId, UserId=@UserId, Author=@Author, Email=@Email, AuthorUrl=@AuthorUrl, Contents=@Contents, EmailNotify=@EmailNotify, IpAddress=@IpAddress, CreateTime=@CreateTime, Approved=@Approved where CommentId=@CommentId ", ConfigHelper.Tableprefix); using (var conn = new DapperHelper().OpenConnection()) { return conn.Execute(cmdText, comment); } }
/// <summary> /// 添加 /// </summary> /// <param name="comment"></param> /// <returns></returns> public int Insert(CommentInfo comment) { string cmdText = string.Format(@"insert into [{0}comments]( PostId, ParentId,UserId,Author,Email,AuthorUrl,Contents,EmailNotify,IpAddress,CreateTime,Approved) values ( @PostId, @ParentId,@UserId,@Author,@Email,@AuthorUrl,@Contents,@EmailNotify,@IpAddress,@CreateTime,@Approved)", ConfigHelper.Tableprefix); using (var conn = new DapperHelper().OpenConnection()) { conn.Execute(cmdText, comment); return conn.Query<int>(string.Format("select [CommentId] from [{0}comments] order by [CommentId] desc limit 1", ConfigHelper.Tableprefix), null).First(); } }
/// <summary> /// 更新 /// </summary> /// <param name="comment"></param> /// <returns></returns> public int UpdateComment(CommentInfo comment) { _recentcomments = null; return _commentRepository.Update(comment); }
/// <summary> /// 添加 /// </summary> /// <param name="comment"></param> /// <returns></returns> public int InsertComment(CommentInfo comment) { int result = _commentRepository.Insert(comment); //统计 new StatisticsService().UpdateStatisticsCommentCount(1); //用户 new UserService().UpdateUserCommentCount(comment.UserId, 1); //文章 //TODO:postservice //PostService.UpdatePostCommentCount(comment.PostId, 1); _recentcomments = null; return result; }