public bool GetFollowed(string followeeOpenId, string followerOpenId) { var dao = new FollowDao(ConfigurationManager.AppSettings["mysqlConnStr"]); bool isFollowed = dao.GetFollowed(followeeOpenId, followerOpenId); return(isFollowed); }
public void FollowByPost(string postId, string followerId) { var graphicMessageDao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]); var graphicMsg = graphicMessageDao.GetById(postId); if (graphicMsg != null && !string.IsNullOrEmpty(graphicMsg.openId)) { var followDao = new FollowDao(ConfigurationManager.AppSettings["mysqlConnStr"]); bool isFollowed = followDao.GetFollowed(graphicMsg.openId, followerId); if (!isFollowed) { followDao.Add(new dataentity.Model.Follow() { followee = graphicMsg.openId, follower = followerId }); } } }
public List <ClubItem> GetClubList(string openId, int count = 10, int endId = int.MaxValue, string filter = "") { List <ClubItem> results = new List <ClubItem>(); var dao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]); string nameFilter = ""; if (!string.IsNullOrEmpty(filter)) { nameFilter = $" and name like '%{filter}%' "; } var messages = dao.GetListExt(filter: $" and isTop=0 {nameFilter} ", count: count, endId: endId); if (messages.Count < count) //如果取出的数量不够,就从头再取,补足不够的数量 { //简单起见,每次到头部的时候,就把置顶文章给带上 var topMsgs = dao.GetTopExt(nameFilter); var compensateMsgs = dao.GetListExt(filter: $" and isTop=0 {nameFilter} ", count: count - messages.Count, endId: int.MaxValue); messages.AddRange(topMsgs); messages.AddRange(compensateMsgs); } if (messages != null) { messages.ForEach(msg => { List <string> pics = new List <string>(); if (!string.IsNullOrEmpty(msg.pic01)) { pics.Add(msg.pic01); } if (!string.IsNullOrEmpty(msg.pic02)) { pics.Add(msg.pic02); } if (!string.IsNullOrEmpty(msg.pic03)) { pics.Add(msg.pic03); } if (!string.IsNullOrEmpty(msg.pic04)) { pics.Add(msg.pic04); } if (!string.IsNullOrEmpty(msg.pic05)) { pics.Add(msg.pic05); } if (!string.IsNullOrEmpty(msg.pic06)) { pics.Add(msg.pic06); } List <string> audioes = new List <string>(); if (!string.IsNullOrEmpty(msg.audio01)) { audioes.Add(msg.audio01); } if (!string.IsNullOrEmpty(msg.audio02)) { audioes.Add(msg.audio02); } if (!string.IsNullOrEmpty(msg.audio03)) { audioes.Add(msg.audio03); } results.Add(new ClubItem() { postId = msg.id, openId = msg.openId, author = msg.author, wechatUrl = msg.wechatUrl, authorHeadPic = msg.authorHeadPic, name = msg.name, poster = !string.IsNullOrEmpty(msg.poster)? msg.poster : msg.pic01, pics = pics, audioes = audioes, itemType = ClubItemType.Graphic, text = msg.text, likeCount = msg.likeCount, commentCount = msg.commentCount, createdAt = msg.createdAt }); }); } //SQL里面已经有order by g.id desc,所以这里不用排序了 //results = results.OrderByDescending(r => r.createdAt).ToList(); int id = 0; results.ForEach(r => { r.id = ++id; }); //如果传入了Follower的openId if (!string.IsNullOrEmpty(openId)) { results.ForEach(r => { var dao2 = new FollowDao(ConfigurationManager.AppSettings["mysqlConnStr"]); bool isFollowed = dao2.GetFollowed(r.openId, openId); r.followed = isFollowed; }); } return(results); }