/// <summary> /// 获取评论数 /// </summary> /// <param name="userid"></param> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> public int GetCommentCount(int userid, DateTime?start, DateTime?end) { string key = Com.GetCacheKey("commentbll.getcommentcount", userid.ToString(), ConvertHelper.GetString(start), ConvertHelper.GetString(end)); return(Cache(key, () => { var _commentDal = new CommentDal(); var count = 0; _commentDal.PrepareIQueryable((query) => { if (userid > 0) { query = query.Where(x => x.UserID == userid); } if (start != null) { query = query.Where(x => x.UpdateTime >= start.Value); } if (end != null) { query = query.Where(x => x.UpdateTime < end.Value); } count = query.Count(); return true; }); return count; })); }
/// <summary> /// 获取评论分页 /// </summary> /// <param name="threadID"></param> /// <param name="page"></param> /// <param name="pagesize"></param> /// <returns></returns> public PagerData <CommentModel> GetComments(string threadID, int page, int pagesize) { if (!ValidateHelper.IsPlumpString(threadID)) { return(null); } string key = Com.GetCacheKey("commentbll.getcomments", threadID, page.ToString(), pagesize.ToString()); return(Cache(key, () => { var data = new PagerData <CommentModel>(); int[] range = PagerHelper.GetQueryRange(page, pagesize); var _commentDal = new CommentDal(); _commentDal.PrepareIQueryable((query) => { query = query.Where(x => x.ThreadID == threadID); data.ItemCount = query.Count(); data.DataList = query.OrderByDescending(x => x.CommentID) .Skip(range[0]).Take(range[1]).ToList(); return true; }); if (ValidateHelper.IsPlumpList(data.DataList)) { var useridlist = data.DataList.Select(x => x.UserID).Distinct().Where(x => x > 0).ToArray(); if (ValidateHelper.IsPlumpList(useridlist)) { var userbll = AppContext.GetObject <IUserService>(); var userlist = userbll.GetUserByIDS(useridlist); if (ValidateHelper.IsPlumpList(userlist)) { data.DataList.ForEach(x => { x.UserModel = userlist.Where(m => m.UserID == x.UserID).FirstOrDefault(); }); } } var parentidlist = data.DataList.Select(x => x.ParentCommentID).Distinct().Where(x => x > 0).ToArray(); if (ValidateHelper.IsPlumpList(parentidlist)) { var commentslist = GetCommentsByIDS(parentidlist); if (ValidateHelper.IsPlumpList(commentslist)) { data.DataList.ForEach(x => { x.ParentComment = commentslist.Where(m => m.CommentID == x.ParentCommentID).FirstOrDefault(); }); } } } return data; })); }
/// <summary> /// 获取评论分页 /// </summary> /// <param name="threadID"></param> /// <param name="page"></param> /// <param name="pagesize"></param> /// <returns></returns> public PagerData <CommentModel> GetComments(string threadID, int page, int pagesize) { if (!ValidateHelper.IsPlumpString(threadID)) { return(null); } var data = new PagerData <CommentModel>(); var _commentDal = new CommentDal(); _commentDal.PrepareIQueryable((query) => { query = query.Where(x => x.ThreadID == threadID); data.ItemCount = query.Count(); data.DataList = query.OrderByDescending(x => x.CreateTime).QueryPage(page, pagesize).ToList(); return(true); }); return(data); }
/// <summary> /// 获取评论数 /// </summary> /// <param name="userid"></param> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> public int GetCommentCount(string userid, DateTime?start, DateTime?end) { var _commentDal = new CommentDal(); var count = 0; _commentDal.PrepareIQueryable((query) => { if (ValidateHelper.IsPlumpString(userid)) { query = query.Where(x => x.UserID == userid); } if (start != null) { query = query.Where(x => x.UpdateTime >= start.Value); } if (end != null) { query = query.Where(x => x.UpdateTime < end.Value); } count = query.Count(); return(true); }); return(count); }