/// <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); }