public JsonResult DeleteCommentReply([FromForm] string token, [FromForm] int commentReplyId) { DataResult dr = new DataResult(); try { if (commentReplyId < 10000) { dr.code = "201"; dr.msg = "参数错误"; return(Json(dr)); } UserEntity userEntity = this.GetUserByToken(token); CommentReplyBLL commentReplyBLL = new CommentReplyBLL(); CommentReplyEntity commentReplyEntity = commentReplyBLL.GetById(commentReplyId); if (commentReplyEntity.fromUserId != userEntity.userId) { dr.code = "201"; dr.msg = "不是你的评论"; return(Json(dr)); } commentReplyEntity.isDel = true; commentReplyEntity.modifyDate = DateTime.Now; int rows = commentReplyBLL.ActionDal.ActionDBAccess.Updateable(commentReplyEntity).ExecuteCommand(); if (rows > 0) { dr.code = "200"; dr.msg = "成功"; } else { dr.code = "201"; dr.msg = "失败"; } } catch (Exception ex) { dr.code = "999"; dr.msg = ex.Message; } return(Json(dr)); }
public JsonResult CreateCommentReply([FromForm] string token, [FromForm] int commentId, [FromForm] string contents, [FromForm] int toUserId) { DataResult dr = new DataResult(); try { if (commentId < 10000 || string.IsNullOrWhiteSpace(contents) || toUserId < 10000) { dr.code = "201"; dr.msg = "参数错误"; return(Json(dr)); } UserEntity userEntity = this.GetUserByToken(token); CommentReplyBLL commentReplyBLL = new CommentReplyBLL(); int rows = commentReplyBLL.Create(commentId, toUserId, userEntity.userId, contents); if (rows > 0) { dr.code = "200"; dr.msg = "成功"; } else { dr.code = "201"; dr.msg = "失败"; } } catch (Exception ex) { dr.code = "999"; dr.msg = ex.Message; } return(Json(dr)); }
public JsonResult PageListByObjId([FromForm] string token, [FromForm] int type, [FromForm] int objId, [FromForm] int pageNumber = 1, [FromForm] int pageSize = 10) { DataResult dr = new DataResult(); try { int totalItemCount = commentBLL.CountUserByTypeAndObjId(type, objId); if (totalItemCount > 0) { List <CommentEntity> commentEntities = commentBLL.ListUserByTypeAndObjId(type, objId, pageNumber: pageNumber, pageSize: pageSize, totalCount: totalItemCount); int[] commentIdInts = commentEntities.Select(it => it.commentId).ToArray(); CommentReplyBLL commentReplyBLL = new CommentReplyBLL(); List <CommentReplyEntity> commentReplyEntities = commentReplyBLL.ListByCommentIdInts(commentIdInts); if (commentReplyEntities.Count() > 0) { Dictionary <int, List <CommentReplyEntity> > keyValuePairs = commentReplyEntities .GroupBy(it => it.commentId) .Select(it => new { id = it.Key, entity = it.ToList() }) .ToDictionary(it => it.id, it => it.entity); commentEntities = (from c in commentEntities join k in keyValuePairs on c.commentId equals k.Key into ck from ckk in ck.DefaultIfEmpty() select(new CommentEntity { commentId = c.commentId, commentReplyEntities = ckk.Value, contents = c.contents, createDate = c.createDate, img = c.img, isDel = c.isDel, modifyDate = c.modifyDate, name = c.name, objId = c.objId, portrait = c.portrait, score = c.score, type = c.type, userId = c.userId })) .ToList(); } PageData pageData = new PageData(commentEntities, pageNumber, pageSize, totalItemCount); dr.code = "200"; dr.data = pageData; } else { PageData pageData = new PageData(null, pageNumber, pageSize, 0); dr.code = "200"; dr.msg = "没有评论"; } } catch (Exception ex) { dr.code = "999"; dr.msg = ex.Message; } return(Json(dr)); }