/// <summary> /// 获得热门主题列表 /// </summary> /// <returns></returns> //[Task("ListForwardItem", "获取列表")] public IList <ThreadsDspModel> GetHotThreadList() { IList <ThreadsDspModel> list = new List <ThreadsDspModel>(); IForumThreadRepository forumThreadRep = Factory.Factory <IForumThreadRepository> .GetConcrete(); IAccountRepository accountRep = Factory.Factory <IAccountRepository> .GetConcrete(); //转换为显示模型 foreach (ForumThread th in forumThreadRep.FindAll(new Specification <ForumThread>(s => s.ForumID != Guid.Empty).Skip(0).Take(5).OrderByDescending(sf => sf.State.MessageCount))) { ThreadsDspModel tmp = new ThreadsDspModel(); tmp.ID = th.Id; tmp.ClickCount = th.State.ClickCount; tmp.MessageCount = th.State.MessageCount; tmp.Title = th.RootMessage.MessageVO.Subject; tmp.UserID = th.RootMessage.Account; try { tmp.UserName = accountRep.GetByKey(th.RootMessage.Account).UserName; } catch (InvalidOperationException) { ///账户不存在 tmp.UserName = "******"; } tmp.LastModified = th.State.ModifiedDate; tmp.CreationDate = th.CreationDate; list.Add(tmp); } return(list); }
/// <summary> /// 获得最近10天内发表的主题列表 /// </summary> /// <returns></returns> //[Task("ListForwardItem", "获取列表")] public IList <ThreadsDspModel> GetRecentThreadList(int days) { IList <ThreadsDspModel> list = new List <ThreadsDspModel>(); IForumThreadRepository forumThreadRep = FBS.Factory.Factory <IForumThreadRepository> .GetConcrete(); //ISpecification<ForumThread> nameSpec = new Specification<ForumThread>(o => o.CreationDate.CompareTo(DateTime.Now.AddDays(-10)) >= 0); DateTime formal = DateTime.Now.AddDays(days * (-1)); IList <ForumThread> forumThreadList = forumThreadRep.GetThread("select * from fbs_ForumThread inner join fbs_Message on fbs_ForumThread.RootMessageID=fbs_Message.MessageID where fbs_ForumThread.CreationDate > '" + formal + "' order by fbs_ForumThread.CreationDate DESC"); IAccountRepository accRep = FBS.Factory.Factory <IAccountRepository> .GetConcrete(); foreach (ForumThread ft in forumThreadList) { ThreadsDspModel temp = new ThreadsDspModel(); temp.ID = ft.Id; temp.ClickCount = ft.State.ClickCount; temp.MessageCount = ft.State.MessageCount; temp.Title = ft.RootMessage.MessageVO.Subject; temp.UserID = ft.RootMessage.Account; temp.ForumID = ft.ForumID; try { temp.UserName = accRep.GetByKey(ft.RootMessage.Account).UserName; } catch (InvalidOperationException) { temp.UserName = "******"; } temp.LastModified = ft.State.ModifiedDate; temp.CreationDate = ft.CreationDate; list.Add(temp); } return(list); }
/// <summary> /// 获得最近10天内发表的主题列表 /// </summary> /// <returns></returns> //[Task("ListForwardItem", "获取列表")] public IList <ThreadsDspModel> GetRecentThreadList(Guid aid) { IList <ThreadsDspModel> list = new List <ThreadsDspModel>(); IForumThreadRepository forumThreadRep = FBS.Factory.Factory <IForumThreadRepository> .GetConcrete(); ISpecification <ForumThread> nameSpec = new Specification <ForumThread>(o => o.CreationDate.CompareTo(DateTime.Now.AddDays(-10)) >= 0 && o.ForumID == aid); IList <ForumThread> forumThreadList = forumThreadRep.FindAll(nameSpec); IAccountRepository accRep = FBS.Factory.Factory <IAccountRepository> .GetConcrete(); foreach (ForumThread ft in forumThreadList) { ThreadsDspModel temp = new ThreadsDspModel(); temp.ID = ft.Id; temp.ClickCount = ft.State.ClickCount; temp.MessageCount = ft.State.MessageCount; temp.Title = ft.RootMessage.MessageVO.Subject; temp.UserID = ft.RootMessage.Account; try { temp.UserName = accRep.GetByKey(ft.RootMessage.Account).UserName; } catch (InvalidOperationException) { temp.UserName = "******"; } temp.LastModified = ft.State.ModifiedDate; temp.CreationDate = ft.CreationDate; list.Add(temp); } return(list); }
/// <summary> /// 根据板块ID获得板块中的主题列表(分页) /// </summary> /// <param name="forumID">板块ID</param> /// <returns>主题列表</returns> public IList <ThreadsDspModel> GetForumThreadListByForumID(Guid forumID, int startIndex, int count) { IList <ThreadsDspModel> list = new List <ThreadsDspModel>(); //创建主题仓储 IForumThreadRepository forumThreadRep = FBS.Factory.Factory <IForumThreadRepository> .GetConcrete(); IList <ForumThread> forumThreadList = forumThreadRep.GetThreadsInOneForum(forumID, startIndex, count); IAccountRepository accRep = FBS.Factory.Factory <IAccountRepository> .GetConcrete(); // return forumThreadRep.FindAll(); foreach (ForumThread ft in forumThreadList) { ThreadsDspModel temp = new ThreadsDspModel(); temp.ID = ft.Id; temp.ClickCount = ft.State.ClickCount; temp.MessageCount = ft.State.MessageCount; temp.Title = ft.RootMessage.MessageVO.Subject; temp.UserID = ft.RootMessage.Account; try { temp.UserName = accRep.GetByKey(ft.RootMessage.Account).UserName; } catch (InvalidOperationException) { temp.UserName = "******"; } temp.LastModified = ft.State.ModifiedDate; temp.CreationDate = ft.CreationDate; temp.ForumID = ft.ForumID; list.Add(temp); } return(list); }
public void Moniter() { while (true) { LoggerHelper.Info("Monitor thread starting..."); IAccountRepository accountRep = Factory.Factory <IAccountRepository> .GetConcrete(); IForumThreadRepository threadRep = Factory.Factory <IForumThreadRepository> .GetConcrete(); IForumMessageRepository msgRep = Factory.Factory <IForumMessageRepository> .GetConcrete(); IBlogStoryRepository blogRep = Factory.Factory <IBlogStoryRepository> .GetConcrete(); IForumsRepository forumRep = Factory.Factory <IForumsRepository> .GetConcrete(); accountRep.PersistAll(); threadRep.PersistAll(); msgRep.PersistAll(); blogRep.PersistAll(); forumRep.PersistAll(); LoggerHelper.Info("Monitor thread completing persist..."); Thread.Sleep(6000000); } }
public ForumController(IForumCategoryRepository categoryRepo, IForumThreadRepository threadRepo, IUsersRepository userRepo) { _categoryRepo = categoryRepo; _threadRepo = threadRepo; _userRepo = userRepo; }
/// <summary> /// 获得精华主题列表 /// </summary> /// <returns></returns> public IList <ForumThread> GetDigestThreadList() { IForumThreadRepository forumThreadRep = FBS.Factory.Factory <IForumThreadRepository> .GetConcrete(); ISpecification <ForumThread> nameSpec = new Specification <ForumThread>(o => o.IsDigest == true); return(forumThreadRep.FindAll(nameSpec)); }
/// <summary> /// 回复帖子的回复 /// </summary> /// <param name="model">回复模型</param> public void ReplyToRepliedMessage(ReplyRepliedMsgModel model) { //IForumThreadRepository forumThreadRep = FBS.Factory.Factory<IForumThreadRepository>.GetConcrete(); //IAccountRepository accountRep = FBS.Factory.Factory<IAccountRepository>.GetConcrete(); //IForumsRepository forumsRep = FBS.Factory.Factory<IForumsRepository>.GetConcrete(); //IForumMessageRepository msgRep = FBS.Factory.Factory<IForumMessageRepository>.GetConcrete(); IForumThreadRepository threadRep = Factory.Factory <IForumThreadRepository> .GetConcrete(); IRepository <ForumThread> threadWriteRep = Factory.Factory <IRepository <ForumThread> > .GetConcrete <ForumThread>(); IRepository <ForumMessageReply> msgRep = Factory.Factory <IRepository <ForumMessageReply> > .GetConcrete <ForumMessageReply>(); IRepository <Forum> forumRep = Factory.Factory <IRepository <Forum> > .GetConcrete <Forum>(); IRepository <Account> accountRep = Factory.Factory <IRepository <Account> > .GetConcrete <Account>(); //获取欲回复的回复 ForumMessageReply readyToReply = msgRep.GetByKey(model.ReadyToReplyMessageID); ForumThread thread = threadRep.GetByKey(model.ThreadID); Forum forum = forumRep.GetByKey(thread.ForumID); //板块 //Forum forum = forumsRep.GetByKey(readyToReply.Forum); //消息对象 MessageVO mVO = new MessageVO(); switch (model.ReplyType) { case ReplyType.Quote: mVO.Body = "<div class=\"quote\">" + "@<a href='" + FBS.Utils.UrlFactory.CreateUrl(UrlFactory.PageName.UserHome, readyToReply.Account.ToString()) + "' target='_blank'>" + accountRep.GetByKey(readyToReply.Account).UserName + "</a><br />" + readyToReply.MessageVO.Body + "</div>" + model.Body; break; default: mVO.Body = "<div class=\"reply\">" + "@<a href='" + FBS.Utils.UrlFactory.CreateUrl(UrlFactory.PageName.UserHome, readyToReply.Account.ToString()) + "' target='_blank'>" + accountRep.GetByKey(readyToReply.Account).UserName + "</a><br />" + readyToReply.MessageVO.Body + "</div>" + model.Body; break; } ForumMessageReply newReply = new ForumMessageReply(mVO, model.User.UserID, forum.Id, model.ReadyToReplyMessageID, model.ThreadID); //更新"吧"的帖子数 forum.AddNewMessage(newReply); forumRep.Update(forum); forumRep.PersistAll(); //更新主题的最后更新时间 thread.ModifiedDate = newReply.CreationDate; thread.AddMessageCount(); threadWriteRep.Update(thread); threadWriteRep.PersistAll(); //向库中增加回帖 msgRep.Add(newReply); msgRep.PersistAll(); }
/// <summary> /// 编辑一个主题的信息 /// </summary> /// <param name="entity">待更新的主题实体</param> /// <returns>是否更新成功</returns> public void EditThread(UpdateThreadModel entity) { //创建主题仓储 IForumThreadRepository forumThreadRep = FBS.Factory.Factory <IForumThreadRepository> .GetConcrete(); try { } catch { throw new UpdateForumThreadException("更新主题至仓储时异常"); } }
/// <summary> /// 创建置顶帖 /// </summary> /// <param name="model">新建置顶帖模型</param> public void CreateTopForumThread(Guid id, string type) { IRepository <TopForumThread> rep = Factory.Factory <IRepository <TopForumThread> > .GetConcrete <TopForumThread>(); //IRepository<TopForumThread> readRep = Factory.Factory<IRepository<TopForumThread>>.GetConcrete(); IForumThreadRepository forumThreadRep = FBS.Factory.Factory <IForumThreadRepository> .GetConcrete(); // ForumThread t = forumThreadRep.Find(new Specification<ForumThread>(s=>s.Id==id)); ForumThread t = null; t = forumThreadRep.GetByKey(id); //NewTopForumThreadModel model = new NewTopForumThreadModel() { CreatTime = DateTime.Now, TopForumID = t.ForumID, TopForumThreadID = t.Id }; if (type == "static") { TopForumThread tf = new TopForumThread(t.Id); try { //rep.Add(new TopForumThread(Guid.NewGuid(),model.TopForumThreadID,model.TopForumID)); rep.Add(tf); rep.PersistAll(); } catch { } } else if (type == "onlyforum") { TopForumThread tf = new TopForumThread(t.Id, t.ForumID); try { //rep.Add(new TopForumThread(Guid.NewGuid(),model.TopForumThreadID,model.TopForumID)); rep.Add(tf); rep.PersistAll(); } catch { } } else if (type == "cancel") { TopForumThread tf = rep.Find(new Specification <TopForumThread>(tft => tft.TopForumThreadID == id)); try { //rep.Add(new TopForumThread(Guid.NewGuid(),model.TopForumThreadID,model.TopForumID)); rep.Remove(tf); rep.PersistAll(); } catch { } } }
/// <summary> /// 根据板块ID获得板块中所有的主题列表 /// </summary> /// <param name="forumID"></param> /// <returns></returns> public IList <ThreadsDspModel> GetAllForumThreadListByForumID(Guid forumID) { IList <ThreadsDspModel> list = new List <ThreadsDspModel>(); //创建主题仓储 //IForumThreadRepository forumThreadRep = FBS.Factory.Factory<IForumThreadRepository>.GetConcrete(); IForumThreadRepository forumThreadRep = Factory.Factory <IForumThreadRepository> .GetConcrete(); IRepository <ForumMessage> msgRep = Factory.Factory <IRepository <ForumMessage> > .GetConcrete <ForumMessage>(); //IList<ForumThread> forumThreadList = forumThreadRep.GetAllThreadsInOneForum(forumID); //IList<ForumThread> forumThreadList = forumThreadRep.FindAll(new Specification<ForumThread>(t => t.ForumID == forumID).OrderByDescending(t => t.CreationDate).Skip(0).Take(100)); IList <ForumThread> forumThreadList = forumThreadRep.GetThreadsInOneForum(forumID, 0, 100); IRepository <Account> accRep = FBS.Factory.Factory <IRepository <Account> > .GetConcrete <Account>(); foreach (ForumThread ft in forumThreadList) { ThreadsDspModel temp = new ThreadsDspModel(); temp.ID = ft.Id; temp.ClickCount = ft.State.ClickCount; temp.MessageCount = ft.State.MessageCount; temp.Title = ft.RootMessage.MessageVO.Subject; temp.UserID = ft.RootMessage.Account; temp.ForumID = ft.ForumID; try { temp.UserName = accRep.GetByKey(ft.RootMessage.Account).UserName; } catch (InvalidOperationException) { temp.UserName = "******"; } temp.LastModified = ft.State.ModifiedDate; temp.CreationDate = ft.CreationDate; list.Add(temp); } return(list); }
public ForumThreadController(IForumThreadRepository forumThreadRepository) { this.forumThreadRepository = forumThreadRepository; }
/// <summary> /// 对主题进行回复 /// </summary> /// <param name="forumThread">主题实体</param> /// <param name="forumMessageReply">回复消息实体</param> public void ReplyThread(ReplyThreadModel model) { //IForumThreadRepository forumThreadRep = FBS.Factory.Factory<IForumThreadRepository>.GetConcrete(); //IAccountRepository accountRep = FBS.Factory.Factory<IAccountRepository>.GetConcrete(); //IForumsRepository forumsRep = FBS.Factory.Factory<IForumsRepository>.GetConcrete(); //IForumMessageRepository msgRep = FBS.Factory.Factory<IForumMessageRepository>.GetConcrete(); IRepository <ForumMessage> msgRep = Factory.Factory <IRepository <ForumMessage> > .GetConcrete <ForumMessage>(); IForumThreadRepository threadRep = Factory.Factory <IForumThreadRepository> .GetConcrete(); IRepository <Forum> forumRep = Factory.Factory <IRepository <Forum> > .GetConcrete <Forum>(); IRepository <ForumThread> threadWriteRep = Factory.Factory <IRepository <ForumThread> > .GetConcrete <ForumThread>(); ForumMessageReply reply = null; ThreadRootMessage rootmsg = null; Forum forum = null; ForumThread thread = null; MessageVO mVO = new MessageVO(); mVO.Body = model.Body; try { thread = threadRep.GetByKey(model.ThreadID); rootmsg = thread.RootMessage; forum = forumRep.GetByKey(model.ForumID); //主题回复数增加 thread.AddMessageCount(); //forum = forumsRep.GetByKey(rootmsg.Forum); //poster = accountRep.GetByKey(model.AccountID); //回复 reply = new ForumMessageReply(mVO, model.AccountID, model.ForumID, rootmsg.Id, thread.Id); //加入板块的最后发表并对板块回复计数 forum.AddNewMessage(reply); //更新帖子 thread.ModifiedDate = reply.CreationDate; //thread.CreationDate = reply.CreationDate; //给主题增加回复 msgRep.Add(reply); msgRep.PersistAll(); threadWriteRep.Update(thread); threadWriteRep.PersistAll(); forumRep.Update(forum); forumRep.PersistAll(); //forumThreadRep.Update(thread); //forumThreadRep.PersistAll(); } catch (Exception error) { throw new ReplyForumThreadException("回复失败,原因为:", error); } }
/// <summary> /// 读取主题所有内容(主贴+回复) /// </summary> /// <param name="id">主题编号</param> public ThreadDetailsModel GetThreadAllContent(Guid id, int pageIndex) { //IForumThreadRepository threadsRep = Factory.Factory<IForumThreadRepository>.GetConcrete(); //IAccountRepository accountRep = Factory.Factory<IAccountRepository>.GetConcrete(); //IForumMessageRepository msgRep = Factory.Factory<IForumMessageRepository>.GetConcrete(); //IForumsRepository forumsRep = Factory.Factory<IForumsRepository>.GetConcrete(); //主题读取仓储 IForumThreadRepository threadRep = Factory.Factory <IForumThreadRepository> .GetConcrete(); //主题更改仓储 IRepository <ForumThread> threadWriteRep = Factory.Factory <IRepository <ForumThread> > .GetConcrete <ForumThread>(); IRepository <ForumMessageReply> msgRep = Factory.Factory <IRepository <ForumMessageReply> > .GetConcrete <ForumMessageReply>(); IRepository <Forum> forumRep = Factory.Factory <IRepository <Forum> > .GetConcrete <Forum>(); IRepository <Account> accountRep = Factory.Factory <IRepository <Account> > .GetConcrete <Account>(); //IRepository<ForumMessageReply> replyRep = Factory.Factory<IRepository<ForumMessageReply>>.GetConcrete<ForumMessageReply>(); ForumThread thread = null; thread = threadRep.GetByKey(id); //thread.RootMessage = msgRep.GetByKey(thread.RootMessage.Id); //不存在该主题 if (thread == null) { return(null); } Forum forum = forumRep.GetByKey(thread.ForumID); //要返回的对象,包括根帖及回复 ThreadDetailsModel target = new ThreadDetailsModel(); target.ClickCount = thread.State.ClickCount; target.Body = thread.RootMessage.MessageVO.Body; target.CreationDate = thread.CreationDate; target.MessageCount = thread.State.MessageCount; target.Title = thread.RootMessage.MessageVO.Subject; target.UserId = thread.RootMessage.Account; target.RootMessageID = thread.RootMessage.Id; target.ForumID = thread.ForumID; target.ForumName = forum.Name; target.UserName = accountRep.GetByKey(thread.RootMessage.Account).UserName; target.LastModified = thread.State.ModifiedDate; target.ForumMessageSum = forum.ThreadCount; //创建回复列表 IList <ThreadsDspModel> list = new List <ThreadsDspModel>(); //从仓储中取出 IList <ForumMessageReply> replylist = msgRep.FindAll(new Specification <ForumMessageReply>(m => m.ForumThreadID == thread.Id).OrderBy(m => m.CreationDate).Skip((pageIndex - 1) * 15).Take(15)); //IList<ForumMessageReply> replylist = msgRep.GetReplyByRootMsgID(thread.RootMessage.Id, (pageIndex-1)*15, 15); //转换回复 foreach (ForumMessage msg in replylist) { if (msg.Id == thread.RootMessage.Id) { continue; } ThreadsDspModel model = new ThreadsDspModel(); model.Body = msg.MessageVO.Body; model.CreationDate = msg.CreationDate; model.UserID = msg.Account; model.UserName = accountRep.GetByKey(msg.Account).UserName; model.MessageID = msg.Id; list.Add(model); } //加到帖子详细模型中 target.ReplyList = list; //点击增加计数 thread.AddClickCount(); //更新thread threadWriteRep.Update(thread); //持久化 threadWriteRep.PersistAll(); return(target); }
public ForumThreadManager(IMapper mapper, IForumThreadRepository forumThreadRepository) { _mapper = mapper; _forumThreadRepository = forumThreadRepository; }
public ForumThreadPostController(IForumThreadPostRepository forumThreadPostRepository, IForumThreadRepository forumThreadRepository) { this.forumThreadPostRepository = forumThreadPostRepository; this.forumThreadRepository = forumThreadRepository; }